In the Middle Ages everybody was scared they were going to Hell. The consensus was, most people were going to spend a few thousand years in purgatory burning off their various sins. But you could pay in advance with penances. Those who were rich and timid could buy indulgences, but for others--especially tough men--the popular penance was ass whippings. The number of strokes was enormous, while the victim repeated a psalm or prayer over and over: "Our Father..." Thwack! "who art in heaven..." Thwack!
It's hard to see how this went out of style. Nowadays most people are so misinformed about this they believe that the Flagellants were considered heretics because of their belief in flagellation. This is a complete misunderstanding. The Flagellants were considered heretics, but this is because they believed (like the Protestants, later) you didn't need a priest to give you absolution--they thought you could atone for your sins without the institution of the Church.
Flagellation itself has never been heretical, and self-flagellation is a practice in very good standing in the Roman Catholic Church to this day. Pope John Paul II practiced self-flagellation, as do many members of monastic orders & Opus Dei.
Flagellation of one man's bare buttocks by another is nowadays not much used as a religious practice. I think it's too bad--our modern society recognizes only the sexual component of this practice, and we are robbed of other possible dimensions of it. In the Middle Ages many a splendid knight in shining armor (and they were sturdy fellows--they worked out with heavy weights, since their armor and weapons were extremely heavy) returned from a campaign of raping and pillaging to inevitable confession and an unavoidable series of long slow sessions with the priest's stinging birch. It wasn't just a few Hail Marys.
Of course this brightened the lives of a lot of celibate priests, but the knight? For most of them, I'm guessing it probably wasn't a sexual experience. Naked before God and His confessor, burning and squirming under the rod's relentless rhythm, he had the opportunity to let himself be transported, from pain to pleasure to ecstasy, surrendering his soul, his mind, his heart--and his behind!--to a higher power. It could be a profound experience of wholeness.
At the very least, they must have felt great when it was over.