The legendary Kubrick comedy Dr. Strangelove is based on the book Red Alert which is in no way comedic. At the time of release, not long after the Cuban Missile Crisis, apocalyptic pessimism was the norm. There was even another movie with a similar plot, Fail Safe released in the same year as a serious drama/thriller.

So how did a serious novel about nuclear doom turn into a comedy? Was it always intended to be a comedy?

After all, what could be more absurd than the very idea of two mega-powers willing to wipe out all human life because of an accident, spiced up by political differeces that will seem as meaningless to people a hundred years from now as the theological conflicts of the Middle Ages appear to us today?

[...]

And it was at this point I decided to treat the story as a nightmare comedy. Following this approach, I found it never interfered with presenting well-reasoned arguments.

In culling the incongruous, it seemed to me to be less stylized and more realistic than any so-called serious, realistic treatment, which in fact is more stylized than life itself by its careful exclusion of the banal, the absurd, and the incongrous.

In the contect of impending world destruction, hypocrisy, misunderstanding, lechery, paranoia, ambition, euphemism, patrioism, heroism, and even reasonableness can evoke a grisly laugh.