"I need help breaking this habit."
Yes, it is now habit...but does it stem from something you need a vet to investigate is more the question.
I am under the impression there is a medical condition that causes the horse to do that stretch part...heard this before.
Let the animal stretch...obviously there is a reason he needs to.
The kick-out seems bad manners though.
If you are going to correct since you know it is going to come, then make it swift and instant & harsh in response not seconds later
cause that is to late..
You also know it is coming and are not/have not
doing anything preemptively to stop it either by your description.
When he starts to stretch...drop him.
Use a rough, gruff voice of quit as the stretch becomes a kick...
As he tightens that stretch in preparation...nail him both with voice and hard swat felt.
Horses are smart, won't take him long to find out he not like what your response is to his bad behavior if you respond accordingly and accurately.
It being a "habit" as you called it...you allowed it to happen, now you must also break the habit created.