A play-within-a-play is a literary device in which an additional play is performed during the performance of the main play. Experts agree that the device is generally used to highlight important themes or ideas of the main play.
Some of the most well-known examples are found in Shakespeare's plays. In "Hamlet," the play "The Mouse-trap" is staged by Prince Hamlet in order to put pressure on the King and to reveal his guilty conscience.
Shakespeare also features a play-within-a-play in "A Midsummer Night's Dream," where Bottom and the other craftsmen put on an unintentionally hilarious version of Pyramus and Thisbe, according to SparkNotes. It is a classic tale of two doomed lovers, which highlights the play's overall message regarding the sometimes absurd nature of love.