The role of the mechanicals is to support two of Shakespeare's central themes in A Midsummer Night's Dream. The two themes are the foolishness of mankind and reality vs. illusion.
We especially see the mechanicals presenting the theme of foolishness in Puck's reaction to their rehearsal. Puck rightly sees that the mechanicals are too uneducated and inexperienced to present a well-performed play, as we see in Puck's line, "What hempen home-spuns have we swagg'ring here" (III.i.70). Not only have they thought of ridiculous solutions to there problems with the play's set, such as having actors play the part of the wall and the moon, they are all bungling up their lines. One example is a line Bottom delivers just before Puck turns him into a donkey, "Thisbe, the flowers of odious savors sweet--" (75). Clearly, odious is the wrong word because it means repulsive or disgusting. Obviously it does not make sense to compare Thisbe to flowers that smell disgustingly. It is this sort of lack of education, coupled with Bottom's conceit, that inspires Puck to turn Bottom into a donkey, proving just what a fool Bottom truly is. Later, Puck expands his judgement of Bottom to include all mankind in his famous line, "Lord, what fools these mortals be!," showing us that the mechanicals help portray Shakespeare's theme that all mankind is foolish (III.ii.116).
The mechanicals also serve the role of portraying the theme illusion vs. reality. The mechanicals have an illusion of putting on a grand performance, but the reality is, as we see, that they are too uneducated and too unskilled. Not only do the mechanicals portray the theme illusion vs. reality, they are the only characters in the play who allow their own reality to be manipulated by their illusions. All other characters have their realities manipulated for them or despite them. They manipulate their own reality by allowing fantasies of their performance cloud their reality; then, when reality hits, we see that the mechanicals' performance is sadly criticized by the royal audience. Hence, we see through the mechanicals that reality is oftentimes influenced by illusion.