Although specific productions may vary in terms of how the play's ending is portrayed, in general the play's ending could be said to have an atypical ending for a romance/comedy. Malvolio is the butt of an elaborate practical joke, and since the character takes himself so seriously, and is possessed of string feelings, his humiliation leads him to storm off after an angry speech. This outburst may dampen the mood of the romantic revelations spoken by the lovers. As well, the fact that the Captain falls in love with Viola when she is dressed like a boy adds what may be an uncomfortable (again, dependent on the production) or awkward suggestion of homoeroticism, which may or may not be resolved when he declares his desire to see her in her "woman's weeds." It is not clear if he will love her as a woman, since, although most productions end with her dressed in feminine clothes, some productions may opt to have her remain clothed as a man. But this sexual ambiguity is common for a number of Shakespeare's comedies that utilize mistaken identity or disguise.
The final ending to the story of "Twelfth Night" shows a song by mean clown Fest, who represented his life as a waste and garbage and sees himself as a "good-for-nothing", a wastrel in fact, unable to find a wife and sleeping with drunken tosspots, his life was terrible and grim and the conditions were equally horrifying and unbelievable.
Why such "gloom and doom" ending towards such joyous and happy story? Shakespeare is trying to add a sense of disquiet and ambivalence amid the joy of the conclusion, so the poem provided some support and confirmation. This poem is one of the most melancholy of the musical numbers in this play, telling us a sad and depressing tale of a clown facing and encountering all of the harshness and difficulties of life that he had experience singlehandedly. Comedy and romance blossomed throughout the epilogue so by portraying this story, Shakespeare is trying to add a bit of gloom and dread and leaves the audience with some sort of unease.
Like the feast that gives the play its name, the story is festive and joyous, but all feast days must come to an end like all good things must come to a stop- life is not a bed a roses, meaning that life won't be easy, there would be difficulties and setbacks. Like the concluding song suggests, it said to "give way to the wind and the rain of life".