The Whipping Boy by Sid Fleischman
Jemmy, once a poor boy living on the streets, now lives in a castle. As the whipping boy he bears the punishment when Prince Brat misbehaves, for it is forbidden to spank, thrash, or whack the heir to the throne. The two boys have nothing in common and even less reas0n to like one another. But when they find themselves taken hostage after running away, they are left with no choice but to trust each other.