This is something I remembered from attending bio lectures with a friend in uni.

Laughter is caused by endorphins produced by a stimulation in a certain part of your brain after something usually profound or exciting. By enduring the flogging, something that you love, it would probably provoke those endorphins being produced.

Similarly, during intense happiness, some people start crying, it's usually at this euphoric point where humans tend to loose their normal control, and the body's natural responses just kick in.