Star Trek can sometimes be a serious affair, showing the issues that modern society faces through the lens of Science Fiction. The Original Series was an attempt to show morality plays as depicted in the future, touching on racism, biggotry, greed and inequality. Star Trek, even when written in a way accessible for all ages, was aimed for a mature audience.
And then, as little rewards for the often serious tone, there are many fine examples of comedy dropped in along the way. Much like any deep dive, one needs to come up for air every so often. In the shows that lean toward the darker, some of the lightest moments exist. In a franchise that has spanned more than fifty years, there are many bright and uplifting episodes where the show not only comes up for air but forces laughing gas down your throat while they're at it.
Not every joke lands and not every situation stands out as funny all these years later (oh Original Series, what a product of your time that you were) but the intent to entertain and to bring an escape has always been there. Even more recent entries like Discovery and Picard have delivered on the laughs and they're both about as serious as the show has become.
But these examples here delve into the chuckles as much as Trek has ever seen, sometimes repeating the gags because they just work so well.