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 working men—Puck notes with contempt in Act III that they have to "work for bread upon Athenian stalls"—who do society's rough labor for low wages. They are not terribly well-educated or knowledgable about the finer points of acting, but they hope to make names for themselves performing the play Pyramis and Thisbe at the Duke of Athen'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 him, head and all, and dotes upon him.
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.