Yes, some horses do masterbate. Usually they'll rub themselves on their bellies though. Not sure if that's what's happening in your boy's case. There is a difference between that and a relaxed male horse just dropping his penis and it getting bumped around a little though.
Got to be one of the funniest things you could possibly imagine.
If we leave a salt/mineral lick in our horses field , our welsh cob will stand over it , get really excited , stand on three legs and pleasure himself to the point of falling over !