My gelding drops out his penis whenever I do any clicker training with him. I clicker trained him to stand still when I say “Stand,” because he was sometimes tricky to mount. It worked well - he stands very nicely when I have to mount him. However, because I clicker trained that behaviour, he drops out his penis when I mount him. It probably looks very weird (my husband saw and asked how my horse walks with five legs), but the horse retracts after we start walking around. He doesn’t ‘air hump,’ or display any studly behaviour when I work with him, so I don’t worry about it. He IS studly in the pasture with mixed groups of horses. He was put in with two fillies (two year olds, I think) at his boarding stable (although I wrote in his file I’d prefer he not be put with mares). However, I let that go because he was fine with the fillies. I could take him away from them without him getting sour about it. Then the stable then put a gelding in there. That did not work out - my horse (gelding) would drive the other gelding to the back of the paddock if he got near the fillies. Because the fillies are always around the hay, the new gelding couldn’t eat. He was put in another pen.
Anyway, it could be that the muscles this horse uses when standing three-footed cause his penis to drop down, which activates the neural pathway that causes the humping motions.
I also did some reading and it’s not uncommon for geldings trained with food to drop their donks out while being trained. Was your horse trained with food to hold his feet up?
https://thehorse.com/17521/geldings-that-drop-during-training/