The main role of the mechanicals in A Midsummer's Night Dream is to provide comic relief, which is often the case with lower class characters in Shakespeare's plays.
The mechanicals are six workings (Puck notes with contempt in Act III that they have to "work for bread upon Athenian stalls") who do society's rough labour for low wages.
They are not terribly well-educated or knowledgeable about the finer points of acting, but they hope to make names for themselves performing the play Pyramis and Thisbe at the Duke's wedding.
Picking Pyramis and Thisbe is a comic choice from the start to celebrate a marriage, as it is a tragic tale of doomed lovers (and a source for Romeo and Juliet).
Events then get even more complicated when the mechanicals enter the upside-down world of the forest on Midsummer's Eve. A magic spell gives Bottom an ass's head, and a love potion means that Titiania, queen of the fairies, falls in love with Bottom, head and all!.
At the end of the play, the fumbling antics and foolishness of the mechanicals as they perform Pyramis and Thisbe adds a comic touch to the wedding.
Overall, the mechanicals take the audience's mind for a time away from the fraught love dynamics of the upper-class main characters while communicating the ways love can make no sense (as in the pairing of Bottom and Titania).
Through their play, they provide as well a counter-narrative that reminds us, if light-heartedly, of the reality that love can come to a tragic end.
One of the Mechanicals’ other functions is to comment on the role of the theatre.
In this respect, they help Shakespeare poke fun at himself and his vocation. This mockery fits in well with the light-hearted, comedic aspect of the play.