I agree about not getting off! He wins if you get off. My new horse did the EXACT same thing. My trainer worked with me several lessons in a row. He was pretty "barn sour" and didn't want to work.
Are you at the walk when he does this? If so, I would anticipate he is going to try to stop and ask for trot a good 20 yards before the gate. Keep him FORWARD. We use "squeeze, cluck, spank" (with dressage whip) as our forward aids. When my horse also started stopping and pinning his ears, I would give up and turn him and just walk him (in the beginning) without upping the "anty". My trainer stopped that quick, especially because he then started a little kick back (a very mini-buck!!) So here I am, advanced beginner, first horse, afraid to get bucked off. I had to get over that fast because he was winning every time. My trainer gave me confidence to follow up with my aids...squeeze, cluck, spank - quick, fast and confident. It only took a few times and he gave up. I held on, was prepared fully to be bucked off and take a spill if I needed to, but I had to do it, or I would never be able to ride him safely as his leader. I survived and conquered and I'm really enjoying my horse now :)
We also do passenger lessons. If you have a fenced ring or area, hold reins on the buckle - resist every temptation to steer. Start at the walk and then trot. Your job (and his) is to control the "gas pedal". He can trot where he wants but he has to stay at the gait that you set. If he drops back down to walk, squeeze, cluck, spank. When he stays at trot leave him alone.
This is a hard exercise but it really works. NO STEERING!! It's also great for your seat and balance.
Now, your guy will definitely trot back to the gate and try to stop. Even if his nose is pointed into the gate latch, squeeze, cluck spank - hold your saddle or mane if you need to and get ready for him to turn or move forward.
Another option (also Clinton Anderson based) is to circle/trot him AT the gate. Make the gate the place you work harder. Do anything to move his feet in FRONT of the gate - make him go backwards (hustle back - not slowly)...yield his hindquarters at the gate over and over in circles. He will soon realize the gate is no fun!
When it's time to rest, let him rest at the furthest corner, nose in corner of ring. Pat him, "good job" etc.
If you up the "anty", stay consistent with your aids, it won't take long to fix. My guy is fixed for the most part but every now and then he tries to stop and pin his ears...and I give him a good hard tap with my dressage whip (after giving him a chance with squeeze, cluck) and it's usually fixed. He is TESTING YOU big time. Be confident, be the leader and you'll be fine. Good luck :)