A few people develop a compulsive urge to crack jokes 24 hours a day, with a medical condition called Witzelsucht. Why does it happen?

Derek’s wife had put up with more than most people could stand before she finally decided to call the doctor. Almost every night, her husband would wake her up from sleep to tell her another bon mot that had just come to mind. In a bid to finally get a good night’s rest, she eventually persuaded him to write them down rather than telling her directly.

Soon, he had filled 50 pages with witticisms such as:

Went to the Department of Motor Vehicles to get my driver’s license. They gave me an eye exam and here is what they said: ABCDEFG, HIJKMNLOP, QRS, TUV, WXY and Z; now I know my ABC’s, can I have my license please?

And

How do you cure hunger? Step away from the buffet table.

They are not exactly the wit of Oscar Wilde, yet Derek (not his real name) would erupt in fits of laughter at these small quips. (Many of the jokes were too rude to repeat in this article.)

As you can imagine, after five years of these inane gags, Derek’s wife found herself at her wit’s end

As you can imagine, after five years of these inane gags, his wife found herself at her wit’s end, and she was also concerned about other strange behaviours – including shop-lifting candy from their local stores. Finally, she arranged to visit the neurologist Mario Mendez at the University of California, Los Angeles. “He constantly cracked jokes during the interview, to the point of being difficult to interrupt,” recalls Mendez, whose report can be found in a recent neuroscience journal.

Mendez diagnosed him with a condition called Witzelsucht (addiction to wisecracking), brought on, it seems, by two strokes, five years apart. As Derek’s family found, the disorder itself is no joke, but exploring this strange compulsion may nevertheless shed light on the complex brain processing underlying a normal sense of humour.

As the doctor started manipulating the cancerous growth, his patient suddenly erupted in a manic flight of speech involving many, terrible puns

One of the first noted cases of this pathological joking emerged in the strangest circumstances by the German neurologist Otfrid Foerster in 1929. Foerster was operating on a male patient to remove a tumour. The man was still conscious – as was common practice at the time – but as he started manipulating the cancerous growth, the man suddenly erupted in a “manic flight of speech”, compulsively recounting pun after awful pun. That same year, the psychiatrist Abraham Brill reported coming across similar patients who would joke about “anything and everything” – even when they were not tied to the operating table.

Since then, many other cases have been noted. Strangely, many of the patients – including Derek – fail to respond to other people’s jokes, despite apparently finding themselves absolutely hilarious. And this may all come from very similar patterns of brain damage in the frontal lobes.

Derek, for instance, had suffered a brain haemorrhage 10 years previously, causing damage in the right frontal lobe. This in itself seemed to bring about a change in personality, leading him to compulsively search rubbish bins for objects that could be recycled – but at that point, he had the same, subdued sense of humour his wife had already known. Then, at some point later, he seems to have suffered a second stroke that damaged the left “caudate nucleus”. This region, lying deep in the skull, seems to act as a hub connecting the frontal lobes (involved in conscious, analytical thought) and the rest of the brain.

The result appears to be the sudden, compulsive joking that was slowly driving his wife around the bend. To understand how that particular pattern of brain damage may explain that awful sense of humour, you first need to appreciate the complex processing that lies behind a joke, such as:

How do you make a Venetian blind? Poke him in the eye.

Or this one, deemed by researchers at the University of Oxford to be one of the funniest jokes in the world:

Three guys stranded on a desert island find a magic lantern containing a genie, who grants them each one wish. The first guy wishes he was off the island and back home. The second guy wishes the same. The third guy says: ‘I’m lonely. I wish my friends were back here.’

Resolving a joke’s puzzle tickles the brain’s pleasure centres, making us laugh

Ok, maybe these quips are funnier when told by a professional comedian. But the point is that each is built around an “incongruity” in the punchline, and your brain must jump through a series of hoops to unpick the logic. You need to grasp the semantic associations in the word “Venetian blind” to grasp the double meaning, and you need to place yourself in the shoes of the people stranded on the desert island. In both cases, there’s an element of surprise as you realise the twist in the tale. Resolving that puzzle tickles the brain’s pleasure centres, making us laugh (or at least, smile politely). “The ‘ha ha’ moment is not very far from the ‘aha’ moment,” explains Jason Warren at University College London.

This brain processing appears to occur in a network of regions around the frontal lobes – the seat of more complex, analytical thought, and the very same areas that are damaged in patients like Derek. “They cannot see the relationship of the punchline to the joke, so they do not show surprise,” says Mendez.

Paradoxically, this brain damage seems to “disinhibit” some of the signalling between those frontal lobes and the pleasure centres. So while others’ jokes may leave them cold, their own thoughts and feelings – stemming from any random connection or association – may end up triggering the dopamine kick as they collapse in fits of giggles.

The findings could be important in predicting the onset and progression of dementia

At least, that’s the theory – and there could be some serious reasons for investigating this kind of disorder further. Warren works with frontotemporal dementia patients – a rarer form of neurodegeneration that “targets people in the prime of their life”. The symptoms include difficulties grasping other people’s feelings and motives. “It plays havoc with their social functioning” – problems that are often accompanied by an impaired (or inappropriate) sense of humour. (Indeed, another one of Mendez’s Witzelsucht patients was suffering from frontotemporal dementia – though not all the patients will be compulsive jokers themselves.)

Warren recently asked these patients to judge various cartoon strips and compared the results to scans of their brain’s grey matter. Sure enough, many were worse at detecting more complex, multi-layered jokes – preferring instead simpler slapstick comedy (such as a drawing of a shocked woman, whose dress had been ripped off her body by a passing car.) And the harder they found the task, the more damage they showed in the “humour network”.

Importantly, he thinks these findings could be important in predicting the onset and progression of the disease. Doctors should take notice if a patient’s families have noticed a changed sense of humour – since it’s often the first cue that something is amiss. “These changes were reported by caregivers years – maybe nine years – before the diagnosis,” he says. Eventually, it might even be possible to develop a more standardised comedy test – similar to the cartoons in his own study – that helps to index changes in their social understanding and functioning.

If nothing else, it should give us a greater appreciation of the hurdles we jump through every time we find ourselves tickled by another’s wit. “Humour is an extremely complex phenomenon, but we often take it for granted,” says Warren. And that, at least, needs no punchline.

David Robson is BBC Future’s feature writer. He is @d_a_robson on Twitter.

Join 500,000+ Future fans by liking us on Facebook, or follow us on Twitter, Google+, LinkedIn and Instagram.

If you liked this story, sign up for the weekly bbc.com features newsletter, called “If You Only Read 6 Things This Week”. A handpicked selection of stories from BBC Future, Earth, Culture, Capital, Travel and Autos, delivered to your inbox every Friday.