One could question just how hilarious Scene 2 in Act 4 is because Malvolio certainly is being treated cruelly; however, one thing that does add to the comedy is dramatic irony. Dramatic irony is when the audience understands far more than the character understands about his/her situation due to limitations.
The moment that Malvolio is tricked into believing that Feste is Sir Topas, the curate is a perfect example of dramatic irony. Pretending to be Sir Topas, Feste talks with Malvolio while he is imprisoned in darkness, under the pretense of finding out if Malvolio has truly gone mad or not. Feste as Sir Topas pretends Malvolio is mad by asserting things like Malvolio is only talking and thinking about women when he asks to see his mistress and also by pretending that Malvolio is not shut up in darkness at all. Malvolio's thinking that Feste really is Sir Topas is an excellent example of dramatic irony because both the other characters and the audience know that Feste is actually playing a trick on Malvolio, while Malvolio has not yet caught on to the trick.
A final touch to the comedy in this scene is that the dramatic irony continues when Feste next speaks to Malvolio as both himself and Sir Topas, as we see in Feste's line, "Advise you what you say; the minister is here," meaning that Sir Topas is standing right beside Feste, but of course Malvolio cannot see that only Feste is present because he is surrounded in darkness (IV.ii.93). Feste says his next lines while again imitating the voice of Sir Topas, "Malvolio, thy wits the heavens restore! endeavour thyself to sleep, and leave thy vain bibble babble," which is to say that Sir Topas is praying that the heavens will heal Malvolio's madness, and he is telling Malvolio to sleep and not babble on so he can heal (94-95). And through all of this, Malvolio never once sees that he is being tricked, believing all along that he is speaking to both Feste and Sir Topas, showing us that Malvolio really is a very foolish person.