This is my humble idea.
A joke loosens/breaks constrains of a specific thought context and we all would love to losen up our tight thinking. A tight thinking which is of pragmatical nature since we had/have to survive and think „straight“.
Comedians often hear „your going to far“ as they hit on strong established mental walls which could lead to danger.
But also in a regular social small talk context the joke jumps out of the regular thought box. This expansion makes us happy, its a tension release.
At-least this was my conclusion when I was high.
And i still think it makes sense.