Sex between two people is a beautiful thing; among five it's fantastic.
The joke works by setting up a sentimental, greeting-card sentence and then wrecking it with simple arithmetic. The first half praises intimacy between two people in a tender, respectable way. The second half assumes that if two is good, five must be better, as though pleasure were something you could multiply like guests at a dinner party. The laugh comes from the gap between the romantic ideal and the greedy logic that sneaks in behind it. The line is widely credited to Woody Allen, though I know of no firm source for it, so treat the attribution as popular rather than certain.
It fits the comic persona Allen built: a neurotic, self-mocking observer who treats big subjects like love and desire with irreverence, in the tradition of the quick one-liner. He tends to puncture solemnity rather than defend it, and the humor admits that human wants are often less noble than we pretend.
Today, the useful takeaway is less about the bedroom than about the "more is better" reflex. Someone planning a modest anniversary dinner might notice themselves adding more guests, more courses and more spectacle, and remember that the quiet version for two was the thing they wanted. Laughing at that impulse is a gentle way to catch it.