The purpose in the mad men dance is actually tightly related to one of the central themes of the play, which is that of deception. The mad men, we are told by Isabella in Act III scene 3, because of their madness, are incapable of deception, and in fact display every thought and emotion that comes into their minds, therefore rendering them "mad" in Elizabethan terms. Note how she describes them to Antonio when the mad men appear in this scene:
Yet are they but our schools of lunatics,
That act their fantasies in any shapes
Suiting their present thoughts; if sad, they cry;
If mirth be their conceit, they laugh again.
What makes the mad men so important is the way that they contrast so strongly to the central characters in this play, who all, in some way, pretend to be what they are not for their own purposes. The mad men therefore act as an implicit criticism on this duplicity, as they present complete honesty, being unable to indulge in subterfuge because of their "madness." The irony of the mad men is that in a play that is so much about lies and deception, the characters labelled "mad" are the most honest.
Insanity was a source of entertainment in the Jacobean age and people would often pay to watch the antics of the insane (think of Londons 'Bedlam' or 'Bethleham' asylum.) It links the subplot to the main plot and also demonstrates how the sexually fraught characters are opporating on a level close to madness. The Jacobean notion of the soul had three levels Rational (human), sensory (animalistic) and the vegitative (plants)... humans should act on the rational however many characters within 'the changeling' are acting on the sensory where they are overtly sexual and bawdy. In a performance I have seen, the dance performance itself was fairly sexual, again showing links with the plays main characters. It is also important to note how these insane and overtly sexual incidences have strong connotations with the court of James I
The dance, though in today's society would seem in poor taste, was back in the Jacobean times, a source of entertainment. It is putting the madness on show allowing people to openly laugh- it would give a greater sense of humour to the subplot. It provides the tool for the meeting of the subplot characters with the main plot characters, as it is put to Lollio to help train the men to dance for Beatrice's wedding. Compared to Beatrice's character being put on show, is it much different? Beatrice has been exposed just like the madmen, and is suggesting where the true madness lies.