Why is Malvolio punished while Maria is not in Shakespeare's Twelfth Night?
In the final scene of Twelfth Night, Malvolio is actually not punished. On the contrary, Olivia actually shows a great deal of remorse for the trick played on Malvolio without her knowledge and offers him the opportunity to be both the accuser and the judge over those who wronged him, as we see in her lines:
But, when we know the grounds and authors of it [the prank],
Thou shalt be both the plaintiff and the judge
Of thine own cause. (V.i.365-67)
However, Malvolio decides not to remain in the household long enough to see justice done and instead leaves, declaring, "I'll be revenged on the whole pack of you" (391). Duke Orsino sends a servant to pursue him, hoping to persuade him to make peace with the household, especially because they need Malvolio to release the captain he has jailed for some offense so that Viola can get her maiden's clothing back and be married.
As for Maria, since Olivia was going to allow Malvolio to be both the accuser and the judge, we know perfectly well that Olivia meant for Maria to be punished in some way. The only reason why she goes unpunished is because she marries Sir Toby. As the wife of Olivia's uncle, it would be improper for her to remain in Olivia's employment since Maria's marriage crosses social boundaries. Hence, we can also assume that after her marriage, Maria and Sir Toby left Olivia's household. We learn of Maria's marriage and, hence, departure in Fabian's lines as he explains to Olivia what had happened and who was involved, as we see in his lines:
... Maria writ
The letter at Sir Toby's great importance;
In recompense whereof he hath married her. (Vi.375-77)
Therefore we see that Malvolio certainly never was punished by Olivia, and the only reason why Maria went unpunished is because she left the household.
Malvolio is punished due to what he generally represents in the play. He is disliked by the other characters (Sir Toby, Maria, Sir Andrew Aguecheek) because he is pompous and wants to assert his "limited" power over others. Maria does not have these characteristics; therefore, she is safe from punishment. Malvolio is a warning to readers for behaving in such a way, while Maria is having fun - teaching Malvolio the exact lesson Shakespeare might be teaching readers. Maria is happy, fun, and desires to have a good time. Thus, she does not have to suffer the same fate for the tricks she plays.
Malvolio also is puritanic in nature. He is conservative, hardworking, and orderly. While these characteristics are generally positive in characters, Malvolio pushes them onto others during a time of celebration. He wants to limit the jovial Christmas celebration that Sir Toby and Sir Andrew Aguecheek enjoy. Shakespeare could also be commenting on the treatment of his contemporary Puritans who wanted to shut down the theaters in London due to their fictional stories and jovial celebrations that took time away from people who could be spending it on more religious studies.