Let us remember first of all that Shakespeare was an actor himself, and many critics believe that the inclusion of two groups of actors in these plays is a funny way in which Shakespeare satirises his own profession and points out the excesses and foibles of actors of his day, even going as far as making fun of specific individuals through the presentation of characters like Bottom and his ludicrous self-importance. We can therefore say that including these plays within a play emphasises the artificial nature of drama as a whole.
However, I think in both of these brilliant plays we can also establish that the play within a play directly relates to the action of both plays and comments upon it. Firstly, if we think of the play of Pyramus and Thisbe, which is played before the Athenian lovers and Theseus and Hipolyta at the end of the play as part of their wedding celebrations, we can see that this play offers us an alternative view of what could have happened. In spite of the hilarious way in which this play is presented, the story is incredibly tragic and could so easily have been the story of Hermia and Lysander. The similarities between the two cases are surely deliberate: both are lovers whose love is opposed by their family and therefore they try to escape and elope together. Perhaps the inclusion of this play is meant to remind us and the characters how often such affairs end up as tragedies rather than comedies.
The Mousetrap, too, serves a more significant purpose than allowing Shakespeare to parody his profession. Let us remember that this is one of the strategies that Hamlet adopts to try and give him incontrovertible proof of his uncle's involvement in the death of his father. As Hamlet says, "The play's the thing / Wherein I'll catch the conscience of the king." Drama is thus shown to be a kind of looking glass that is held to the audience to show us our own faults and excesses. Just as watching this play forces Claudius to reveal his guilt, so to are we confronted by our own failings by having them mirrored to us through the medium of the stage.