It is Hamlet who calls the play within a play The Mousetrap because he intends to use it to catch a rat (Claudius). The play in Act III is about a king who falls asleep in his garden, and another man who comes and pours poison into the sleeping man's ear then steals his crown. This mirrors the story that the Ghost of Hamlet's father told Hamlet about his own death.
Hamlet is not sure whether or not to trust a ghost, so he comes up with this plan to watch Claudius' reaction. If he is innocent, then Claudius will placidly watch the play. Claudius becomes enraged at the play and screams for more light, thereby proving to Hamlet his guilt. At that point, Hamlet decides that he must trust the Ghost and kill his uncle in order to avenge his father's murder.
So some issues reflected are:
- sons taking revenge for fathers' murders
- Claudius's murder by poison of Old King Hamlet
- appearances of truth and falseness
- trickery to learn secrets (e.g., Polonius eavesdropping)
- the roles of Ophelia and Gertrude in relation to Hamlet and Claudius
- guilt or innocence of Gertrude and Ophelia
- love and treachery
The play within a play imitates almost precisely what Hamlet suspects has happened to his father and mother, but who told him what happened? His father's ghost! So The Mousetrap is used to verify, or prove to Hamlet, beyond a shadow of a doubt, that his father's ghost was real, for one thing.
Up till he stages this play, he is not absolutely certain the ghost is real, is telling the truth, is anything more than figment of his overactive imagination. So think of the play within a play as Hamlet's rational, university-educated, scientific mind trying very hard to come to grips with something his senses tell him cannot be true, but nonetheless is true, which is that ghosts exist, and that they are capable of speech.
So The Mousetrap functions as a test for Hamlet. He will determine, from Claudius' and Gertrude's responses, whether or not his father's ghost is telling the truth; he will also determine for himself whether or not he has the proof he needs to enact revenge upon Claudius as his father has commanded him to do.
But The Mousetrap is also a threat to Claudius, because it reveals that Hamlet knows, and it makes Hamlet a risk, in the same way that a murderer who is found out in a murder mystery, must be silenced. So there is a deeper theme of silencing going on in "Hamlet," the need to keep secrets, and never reveal too much of what is really going on--in the family, between Hamlet and Ophelia, and the ultimate secret of who killed the King.