This is a fairly common reaction, and especially when new. And while the trainer pulled you, probably because he figured you might get hurt reacting this way, the best and near only way to overcome it is to get more experience with getting hit. Now that you are aware of it, you will just have to buckle down.

It is also fairly common for people to move their head too far back in their stance, an instinctual reaction from the brain trying to keep one's head furthest from incoming punches. The prob is it often leaves the chin up in the air, and further away from the hands and reaction time to defend punches. I see more people getting nailed like this then anything.