Well, not to give a lazy answer but only because I assume Google could explain it better than I possibly could:
“Being whipped triggers the body’s natural “fight-or-flight” response, causing the brain to release a flood of endorphins as a protective mechanism to numb the pain. These chemicals act as natural painkillers and mood elevators, ultimately resulting in deep relaxation, stress relief, and feelings of euphoria once the stimulus stops.”
Hopefully that answers your question :).