There is no particular origin or meaning for this rhyme, however its’ enduring popularity probably is attributable to the Lewis carroll book Alice in Wonderland.
It was first published in 1805 by Charles Lamb in his nursery rhyme book.
“The Queen of Hearts” Lyrics
The Queen of Hearts,
She made some tarts,
All on a summer’s day;
The Knave of hearts,
He stole those tarts,
And took them clean away.
The King of Hearts
Called for the tarts,
And beat the knave full sore;
The Knave of hearts
Brought back the tarts,
And vowed he’d steal no more.