Whipping boys existed in the English court in the middle ages. King’s aides were forbidden to punish the prince, so they would give the prince a normal friend and then take it out on him if the prince misbehaved.
Summary from Source
A whipping boy was a boy educated alongside a prince in early modern Europe, who received corporal punishment for the prince's transgressions in his presence. An archaic proverb which captures a similar idea is "To beat a dog before a lion." Whipping was a common punishment of tutors at that time. There is little contemporary evidence for the existence of whipping boys, and evidence that some princes were indeed whipped by their tutors, although Nicholas Orme suggests that nobles might have been beaten less often than other pupils. Some historians regard whipping boys as entirely mythical; others suggest they applied only in the case of a boy king, protected by divine right, and not to mere princes. In current English, a "Whipping boy" is a metaphor which may have a similar meaning to scapegoat, fall guy, or sacrificial lamb; alternatively it may mean a perennial loser or a victim of group bullying. Alessandro d'Ancona sees an antecedent of the Conrad novella in Phaedrus' fable "The Bullock and the Old Ox". Henry FitzRoy, 1st Duke of Richmond and Somerset, whose tutor Richard Croke complained in 1527 that Richmond's usher, George Cotton, was undermining Croke's authority; among the charges were withdrawing "Those boys whose punishment it was necessary to deter his princely pupil from the repetition of his faults", and claiming it was unseemly for Croke to whip them in Richmond's presence. An adult example often included in discussions of whipping boys is provided by the French Catholic prelates Arnaud d'Ossat and Jacques Davy Duperron, who were symbolically whipped by Pope Clement VIII in 1593 in proxy expiation on behalf of Henry IV of France, who had renounced Protestantism.
Cranmer says, "Since he was whipped thus for the prince's faults. / His grace hath got more knowledge in a month. / Than he attained in a year before, / For still the fearful boy, to save his breech, / Doth hourly haunt him, wheresoe'er he goes." The prince persuades king Henry VIII to knight Ned: "The poor gentleman was pitifully wounded in the back parts, as may appear by the scar, if his knightship would but untruss there". Ned hopes the tutors will refrain from whipping a knight, to which the fool retorts, "If they do, he shall make thee a lord, and then they dare not." This work may have helped the idea of a whipping boy to take root. The Whipping Boy by Sid Fleischman, which won the 1987 Newbery Medal for children's books, tells of the brattish Prince Horace who learns humility on an adventure with his whipping boy, a rat-catcher named Jemmy. In George R. R. Martin's fantasy series A Song of Ice and Fire, published from 1991, the characters Tommen Baratheon and Joffrey Baratheon have a whipping boy named Pate. In David Belbin's 2002 children's novel Boy King, Barnaby FitzPatrick is whipped by John Cheke for teaching Edward VI swear-words; when Edward protests that nobody has whipping boys any more, Cheke says "The Duke of Richmond had one". Cheke relents from giving FitzPatrick the whipping owed to Edward. Sarah Ruhl's 2016 play "Scenes from Court Life, or The Whipping Boy and His Prince" includes whipping boys in its depictions of Charles I and Charles II of England. Biram Dah Abeid has alleged that slaves in Mauritania are used as souffre douleurs or whipping boys.