Madness was often associated with falling in love in Shakespearean plays. Shakespeare stressed, through example, that love makes people do crazy, uncharacteristic things. It makes people resort to desperate measures to attain the love of their chosen one. In all of his romantic comedies, we see many examples of how characters will go to great lengths to obtain the object of their love. Romeo and Juliet, A Midsummer Night's Dream, and Twelfth Night are all plays that Shakespeare wrote in which characters do things that are ludicrous, out of character, or humorous.
Poor Malvolio is made an example of when Uncle Toby helps land him in jail for lunacy when in fact, he is simply in love with Olivia. Malvolio goes "overboard" to show Olivia how much he loves her and appears arrogant and overconfident about what he perceives might be her feelings for him. She must consistently assure him that she does not love him. He does not give up, however, until the end, when it is revealed that he has been made a fool of by Uncle Toby, Maria, etc. He then reacts angrily and decides he will exact revenge upon them for how they have ridiculed and embarrassed him. The reader might feel somewhat sorry for him, but others might see his punishment (his "jail stint") as adequate for making such a fool of himself for love. eNotes states:
Indeed, when he speaks finally of exacting revenge in Act V, Malvolio evokes a certain sympathetic understanding. Malvolio has been abused as the target of a trick perpetrated by the parasitical, self-serving Uncle Toby. For his part, Uncle Toby, Malvolio's chief tormentor, is a merry soul, but he is also a rouge who is scheming to marry his fair niece to the absurdly non-heroic, non-romantic figure of Sir Andrew. If we view the play as a standard romantic comedy, Malvolio warrants the comedown that he undergoes; but as a matter of justice, Malvolio has done very little to earn a humiliating payback.