I think Heinlein nailed it in Stranger in a Strange Land. Humor is a reaction to pain, and may have evolved like a hiccup. A stress relieving burp that has evolved with the types of stress our minds can invent.
> I think Heinlein nailed it in Stranger in a Strange Land.
Also in _The Moon Is a Harsh Mistress_ he made the research of what is humour be one of the primary self-assigned directives of Mike (the accidentally created GAI).