Good question. The rude mechanicals have many parts/functions.
Mostly simply, they provide humor.
They also provide a different kind of humor. Bottom's egotism is distinct from the slapstick of the lovers.
They provide perspective on the love affairs of the play. The young lovers could have ended like Pyramis and Thisbe, but instead, the fairies intervened.
They provide perspective on theater; consider the last act.
Bottom is a tool through which Oberon can torment Titania.
Finally, they show the play reaching to society's lower levels, as the king shows it reaching to the upper.