He might've done it the first time simply to test you, perhaps deciding he was done working, found out he could get away with it, then decided he could be a jerk.
Bomber, a horse i frequently ride, often times tests me. if i let him gegt away with it, even just once, he will do it for the rest of the lesson. But if i am firm from the beginning (with the occasional bribery before lessons, a carrot before lessons always puts him in such a good mood), then he is a charm. But with Bomber its hard to tell, he's always making faces.