This rhyme has existed in the form we know it for at least 200 years. But 2,000 years before you first sang it, your great-great-great-(add 80 more greats)-grandparents were doing almost the same thing.
In Roman times children would play a game, while singing and taunting each other, ‘You’ll be king if you do the right thing, and if you don’t, you won’t.’ It’s almost as catchy in the original Latin: ‘Rex erit qui recte faciet, qui non faciet, non erit.’
That’s the Continental origin, but an alternative version surfaced on the other side of the Channel during the English Civil War. In 1651, a Scottish officer called John Cockburn was defending his fortress, Hume Castle, from Oliver Cromwell’s English invaders. Refusing to surrender, he sent them the following letter:
I William of the Wastle, Am now in my castle; And awe the dogs in the town, Shan’t gar me gang down.
We don’t know if Cockburn made this up himself or whether he was repeating well-known doggerel of the time. Either way, it didn’t work: the castle walls were breached, and Cockburn and his men were forced to leave. But the rhyme outlasted his battlements, becoming popular and morphing into the one we know today. And so, in the British Isles at least, the English were the original dirty rascals to the Scottish king of the castle.
This question was answered by the QI Elves, and extracted from Funny You Should Ask … Again: More of Your Questions Answered by the QI Elves, published by Faber & Faber at £12.99: