I frankly think most of the better-known real life stories about such "moonlightings" are unproven myths, so I'm going to keep it straight to fiction:
1. Arthur Conan Doyle: A Scandal in Bohemia and The Illustrious Client
Representatives of the British government and nobility ordinarily don't have a problem showing up in Holmes's rooms in their own person, but when it comes to royalty, things are different: The King of Bohemia initially shows up pretending to be a certain Count Von Kramm (OK, still nobility, but from a hereditary king's perspective, almost as lowly as a commoner); and while we never actually learn the identity of the "illustrious client" sending an emissary to Holmes in the other story, Watson implies at the end that the client in question was none other than King Edward VII.
2. Terry Pratchett: Wyrd Sisters
A switcheroo turning a prince into an actor and, eventually, the Duke's fool into the new ruler. Also one of the funniest books in the entire Discworld series (and a brilliant spoof on Shakespeare's Macbeth and Hamlet).
3. J.R.R. Tolkien: The Lord of the Rings
Aragorn, rightful heir to the throne of Gondor, bides his time as a ranger for the better part of the trilogy.
4. Mark Twain: The Prince and the Pauper
Henry VIII's son, Prince Edward VI, and a young boy named Tom Canty switch places for a while, and the experience of being exposed to Tom's miserable life and the brutality of his alcoholic father has (as Twain would have it) a salutary effect on Edward's understanding of class issues and sense of justice, once he is crowned king.
5. C.S. Lewis: The Horse and His Boy
The titular "Boy" is Shasta, who has grown up as a fisherman's son, but after escaping from his ruffian adoptive father and numerous subsequent adventures is eventually revealed as the son and heir to the king of one of Narnia's neighboring countries.
6. Jennifer Estep: Kill the Queen
Evil princess massacres her mother (the queen) and her entire court; thus her "poor cousin" (who is actually next in line for the throne) hides with a band of gladiators, learns to fight, and eventually faces down the evil princess to take her throne for herself.
7. William Shakespeare: As You Like It, Pericles, The Winter's Tale, and Cymbeline
In As You Like It, Rosalind, the exiled daughter of the regining duke (Duke Senior) masquerades as a page for the better part of the play.
In Pericles, the titular Prince of Tyre's daughter Marina is kidnapped and sold to the owners of a brothel (where she manages to keep her virginity by lecturing the customers on their sinful ways ... sigh. Really, Will?)
In The Winter's Tale, the Sicilian royal couple's daughter Perdita is raised by a shepherd who has found her bundled up as a baby after she had been abducted from the palace.
In Cymbeline, the eponymous king's daughter Imogen also disguises as a page at one point.
1. Dorothy L. Sayers: Have His Carcase
A commoner is bamboozled into falsely believing himself a member of the House of Romanov.
2. Alexandre Dumas: The Man in the Iron Mask; and Anthony Hope: The Prisoner of Zenda
The rightful heir to the throne is kidnapped and replaced by a doppelgänger (but the kidnapped royal is not passed off as a commoner).
3. Roman Holiday (movie)
I'm not much into romance, but Audrey Hepburn and Gregory Peck are such a treat they just have to make an appearance on this list.
(Task: Towards the end of the 17th century, there was a Russian apprentice carpenter and shipwright going by the name Peter Mikhailov in the Dutch town of Zaandam (and later in Amsterdam), who eventually turned out to be none other than Tsar Peter the Great, whose great interest in the craft would become pivotal to his programs for the build-up of the Russian navy and naval commerce.
So: Tell us about a favorite book, either nonfiction history (demonstrably true facts, please, no conspiracy theories or unproven conjecture) or fiction – all genres, not limited to historical fiction –, dealing with a member of royalty “moonlighting” as a commoner.)