he humor point
When things make sense after the confusion and delay, then we find things funny.
Relief
When people have been in danger or are threatened by some risk, it is common for them to laugh when the threat has passed. This is a form of closure, where the tension of the perceived risk is released.
The same principle happens with humor, where the confusion, which raises the possibility of threat, is resolved. This is a kind of relief, where we can relax and smile.
Safe danger
One of the things we enjoy is 'safe danger', where we can experience threats that are not really threats, for example in the vicarious experience of watching contact sports or horror movies. Jokes and funny situations act in a similar way as the uncertainty creates a sense of danger, yet we know we will not be harmed.
One view of the origin of laughter is where a parent whizzes a child up and down and the child makes smiling breathless 'huh, huh' noises as they enjoy the thrill of the 'danger' in the movement.
Learning
Jokes are not so funny when told again, as there is no surprise or confusion the second time around.
When we make sense of something that formerly did not make sense, we are learning. Young children learn through play. Humor can be deliberately used as an integral part of education, making learning fun again.
Creative aha
In another way, this is like creativity, where there is a delay between looking for an idea and the aha of discovery. The tension of seeking a solution prompts the brain to come up with a new idea. The closure of the 'aha' moment can feel a lot like humor and the person may well laugh.
Pain and pleasure
Humor also leans on the fundamental principle of pain and pleasure. The discomfort of not understanding is a form of pain, while the sudden realization is a form of pleasure. As these rapidly sequence together, the resultant feeling can be a strange mingling of both pain and pleasure at the same time.
Good and bad jokes
Good jokes make use of timing, aligning description by the teller with the thinking and understanding process of the listener. In this way, the person is already trying to make sense of what is said before the end of the joke/ The punchline acts as a control element when it is necessary and sufficient to trigger final understanding.
A bad joke either does not lead to confusion as the audience understands it easily, or else it just leaves them confused. Bad jokes make people irritatedly think 'hah' rather than the funny 'aha' (or perhaps 'haha') of understanding.