Take what I say with a grain of salt.
Learn psychology. All the human behaviours, motivations, and thought process.>Here is a quick start guide.
Watch comedy, all the funny things all the time. From ages past. The classics. Standup, to cartoons.>Beware, some 'comedy' is just malicious brainwashing, and manipulation. SJW stuff is cancer due to it being just behavioral modification, and self justification.
Doesn't matter if it isn't funny to you atm. The next part is to just smile. Especially if you don't actually feel happiness, joy, or mania at the moment.
At the punchline to the joke, when you hear the audience laugh, AND
you find it funny laugh. Laugh like you really mean it. Make sure to keep smiling.
Like most things about people we don't actually know everything, and sometimes we're just wrong in our theories.>Think of humor, like a tickle.
It's when it's not really harmful mostly everyone has fun. Most of the time it's involuntary (subconscious roles).
When it is harmful the target isn't having fun, and most others don't like it.
But not always. It's an interaction between The comedian, the audience, their (or the target's) mostly collective idea of how the world is, and the joke.
The comedian plays the joke. As a musician would music. (It's a game without the player, it NEEDS the recipient to reach it's full potential.)
The joke does something to the targets' mind, mental structure, or perceived insight, or perception, or the alteration (twist) of the perception. It Shows SOMETHING to the person.
The World View (Mental State) of the target is needed to be taken into consideration to create the joke. The Creator of the joke needs to find something to show them worth showing.
The Audience finishes the joke. More accurately it's the conscious, and subconscious that complete it.
That's my current theory.