In Shakespeare's Hamlet, the play-within-the-play, which Hamlet tells Claudius is titled, The Mousetrap, creates suspense by providing a way for Hamlet to know if the Ghost is telling the truth about King Hamlet's death. Thus, as Hamlet waits to see Claudius's reaction, so does the audience. That's suspense.
Throughout the play, virtually no one in the play is what they seem, or more specifically, no one is playing the role that is expected (Hamlet acts insane, Ophelia, Rosencrantz, Guildenstern, Polonius, and Claudius all act as spies, etc.). Hamlet himself raises the issue of seeming when he insists that others may only seem to be in mourning, but he genuinely is in mourning. Continuing this theme, The Mousetrap seems to be only a simple entertainment, but in reality is a trap. And Claudius seems to be innocent to the people of Denmark, but is not. The Mousetrap is Hamlet's means of exposing the truth--at least to himself.
The play, and Claudius's guilty reaction to it, give Hamlet corroboration for the Ghost's story. This frees Hamlet to morally kill Claudius. It also sends Claudius into a figurative tailspin, moving him to an emotional prayer. The play should conclude when Hamlet finds Claudius at prayer and has a chance to kill him. It doesn't, however, because Hamlet doesn't want to send Claudius to heaven by killing him as he confesses. And this leads to the climax of the play.
Hamlet goes beyond his station in life when he attempts to determine another human being's eternal salvation. When he doesn't kill Claudius he is guilty of hubris (acting above one's station in life), and he dooms himself and numerous others.
Thus, The Mousetrap leads directly to the climax. And though Hamlet's plan works--the mouse is trapped--and Hamlet wins the cat-and-mouse game he's been playing with Claudius, the play-within-the-play also leads to the climax and Hamlet's doom.