The Marx Brothers changed the way comedy works in film, literally re-inventing the genre for the Twentieth Century, but when they were at their most successful in A Night at the Opera, they were following a tried a true formula that is as old as... well... The Merry Devil of Edmonton. See if you can tell which I'm talking about by this description: a pair of lovers is helped by a group of clowns who foil the schemer trying to ruin their future bliss.
The reason this formula works so well is dead simple: the audience's sympathies are automatically with the lovers. The greedy and vain villains become the target for the clowns, whom we cheer on. There's no need for us to feel any reservations about the rightness of what the clowns are doing because we want to see the lovers win, and anything that stops the villain from ruining their true romance makes us feel good inside. Any other casualties of the clown troupe are victims of the greater good, and so we might feel some pangs for them, but ultimately we'll know that they needed to get punk'd in the name of true love.
Both Merry Devil and A Night at the Opera would function as straight up dramas, but at the end of the show, you can expect both the lovers and the clowns to get what they want. The mere presence of the clowns implies the happy ending of the comedy, and that makes all the travails that the lovers go through that much funnier. We can laugh at a romantic lead crammed into a suitcase or dragged through the mud as long as we know there's a wedding waiting for them before the curtain comes down.