What is the relationship between humor and logic?
A joke is like an argument. The punch line is the conclusion. We follow the logic of the "premises" and know what we should expect at the end of the "argument." What makes the joke funny is how the conclusion does not follow logically from the premises.
Is the punch line -- conclusion -- a pun? Then a word or words are used in a different sense in the conclusion than we were led to expect from the premises. Example: Why does a little baby duck walk softly? Answer: A little baby duck can't walk hardly.
Is the punch line a non sequitur? (does not logically follow). Dave Barry is a master at this!
But many of our jokes are simply fallacies that are deliberately made so that we can see the "joke."