There is a notable book called Laughter by French philosopher Bergson. Its argument is that comical effects are reducible to something mechanical (mathematical) (mis)applied on some living thing.
This could be a better explanation than what I read here and in the article.
If you're interested in the subject, see Inside Jokes: Using Humor to Reverse-Engineer the Mind by Hurley, Dennett, and someone else. They critique Bergson (and many others) and conclude something interesting but which I can't remember because I'm traveling and don't have the book handy.
This could be a better explanation than what I read here and in the article.