In Act III of Hamlet, the play-within-the-play reveals the crimes Hamlet’s uncle committed, and it was meant to become a lesson for him. Since the Elizabethan drama is characterized by describing human nature and their everyday sins, the play-within-the-play scene used in Act III is its perfect representation.
The truth about how Hamlet’s father was murdered is revealed in Act III. After Hamlet finds out that his uncle is a murderer, he comes up with the idea to set a “mousetrap” for Claudius to see if it is true. Moreover, he needs some proof that his father’s ghost, who was the source of the revelation, isn’t just in his mind. Using the help of the traveling acting troop, he sets up the play (ironically naming it “The Mousetrap”), which plot is amazingly similar to his father’s murder scene. All that is meant to observe the reaction of Hamlet’s uncle. During the play, the King storms out, which implies his guilt.
Hamlet used this play-within-a-play to discover whether his doubts about the king are true - he reenacts the events from his "real" life where Claudius indeed killed the previous king to see whether he will reveal himself as the murderer. He wants him to know that he knows of his evil doings and that he is on to him.