The ending of this play, in particular, really harps on the dichotomy between tragedy and comedy. Twelfth Night, of course, is a comedy, but its only characteristic is not that it amuses the audience and creates a drama-filled plot; but it also, in suspense, becomes a tragedy as the laws of gender are bent and the presentation of identity is skewed, and women are almost marrying other women disguised as men (gasp!).
Of course, to keep it happy and without controversy, all is set right again in the end–Viola and Sebastian realize they are twins; Malvolio realizes he has been wronged and that he is not actually insane; Viola reveals that she embodied Cesario in order to assume a role as a male and gain more employment and respect.
This is the one thing that bothers me about Shakespeare the most, but it also speaks to his time. Of course, in Europe at this time, there were rules and regulations associated with homosocialization, homosexuality, and gender roles and identity, that were very blatantly binary oriented. While it speaks to the times, I don’t think it means at all that Shakespeare, in writing really strong women characters (who we would today consider to be feminists,) and bending gender rules and perhaps envoking modern conversation of queer theory, can be considered a progressive or forward-thinking writer, because he sets it all backwards and diverts back to the norms in an effort to please everyone, especially in a Christian-centric geographical location and era.