A marketing and psychology researcher has studied what makes stuff funny, and he came up with the above formula as to the reason why.
Basically, Peter McGraw found that most jokes have roots in something that did go wrong or could have gone wrong. A wry observation of sorts too soon after the event is found unfunny because not enough time has elapsed for the pain to ease. But too long after the event and the joke has no relevance anymore.
The event doesn't have top be a real tragedy, just something slightly amiss or awry will do. So-called "dark humor" is usually done in that too-close-to-the-event time frame, and my own personal thought is that many of these jokes -- riffs on high-profile tragedies, for example -- originate in newsrooms. Some of my reasoning on this matter comes from my experience in said newsroom, which involved the creation of some of this mordant mirth. My time at college was spent hanging around news-minded students, that being my major, and so I heard many of these jokes in the wake iof the headlines. I had one non journalism-major friend, in fact, who refused to take my phone calls the day of any remotely sad event for fear I would have heard one of these woeful witticisms and be trying to pass it on.
In any event, I repent of those sins (and I'll probably have to do so again). And I can think of a number of blogs I've read whose writers thought themselves satirists who should scan this little article and learn from it. I'll sure try to.