Humour often involves saying something that isn't true (why don't ants catch colds? Because of they have anty bodies - great joke but not true on a number of levels). A surprising number of humans don't have the mental cycles available to consider counterfactuals, hypotheticals or entertain ideas that aren't directly rooted in reality. I suspect that means they can't process humour and they just laugh if the crowd is.
It goes beyond humour, you can see it in a lot of scenarios and it ruins politics. There are people who appear literally unable to consider hypothetical scenarios. Not in a nasty way, they're sometimes wonderful people to have on hand. They simply only deal in reality as they see it. You can walk them slowly through a "and what if ... happens?" and they can't do it.
I once dated someone who couldn't consider hypotheticals or how they could be used as a reasoning tool. Disagreements were the most frustrating thing ever because I couldn't play devils advocate or steelman. She thought I was agreeing with her intermittently to make her mad. She had no concept of walking in someone else's shoes or arguing a position you don't actually hold. It blew my mind.
(Human) Humor is a far broader spectrum than you describe here too. It can range from "ROFTL because someone accidentally stepped in poop" to deeply layered liguistic jokes like you describe.
> One aspect of humor depends on cognitive flexibility
All humor? (Honest question)
I was under the presumption that e.g. slapstick or schadenfreude humor doesn't need linguistics, and is therefore seen in many animals. Animals that don't have any form of language but do have rather intricate social systems or even ranks and caste systems. but do have humor. E.g. where breaking or pushing those systems is the humor.