|Ca, 1912 illustration of an inmate being punished|
in an American prison
The metaphor is probably a reference to a prisoner being strapped over a barrel and flogged. Literal references to a barrel being used for flogging date back to the 19th century. This poem from 1869’s Nonsense by Brick Pomeroy uses over a barrel to refer to children being punished by a schoolteacher:
I’d like to be a school-marm,
And with the school-marms stand,
With a bad boy over a barrel
And with a spanker in my hand
There is also a reference to using a barrel as part of the treatment of a drowning victim. The mode of treatment is to roll the patient over a barrel, as if he were drowned only in the bowels, and it was expected that, by dislodging the water at that point, the victim would soon be revived.
The flogging metaphor, however, fits the meaning of the modern use much better than the drowning metaphor and therefore seems more likely as the origin.