
This sounds like he gets overexcited and is then sexually aroused, at a guess I would expect he was castrated at the silly ovesexed teenage stage and this has now become a habit that he didn't grow out of.
What looks like his innards coming out is just the engorged Gland at the base of a dogs penis (looks like a second set of testes), which is what would help the tie during mating keeping the dog inside the bitch.
The best thing is to totally ignore it as he may find the attention rewarding, and also don't allow people to fuss him to the extent where this happens.
If it happened at home then you could use a clean flannel with ice to help the engorgement go down more quickly, or a bag of frozen peas.
As you have found castration doesn't necesarily make a dog uninterested in sex.