What is the function of a play within a play (Pyramus and Thisbe) in "A Midsummer Night's Dream"?
The "play-within-a-play" concept was one Shakespeare used often (see "Hamlet" and "Love's Labor's Lost"). The play in "A Midsummer Night's Dream" has a few functions.
First of all, it provides a bit of relief after the entire play--a chance for the audience to take a look at something completely inane and funny, which is ironic because one might consider that the lovers in the forest might have been acting a bit inane and silly as well.
IT also cements the relationships between Hermia and Lysander, Helena and Demetrius, Hippolyta and Theseus and Titania and Oberon--they are in contrast to the doomed love of Pyramus and Thisbe.
Shakespeare also put the awfully produced play in Act Five of his play in contrast to his--he hopes that the audience will receive his play better than the mechanicals' play is received by the lovers. However, it could also be Shakespeare indicating that the audience shouldn't take "A Midsummer Night's Dream" too seriously. This connects with Puck's epilogue--"We we spirits have offended/think but this and all is mended..." It's up to you to make the call on this part.
Hope this helps!