Wiktionary
alt. (context US idiomatic English) comedy that still manages to be funny in the face of, and in response to, a tragic or hopeless situation. n. (context US idiomatic English) comedy that still manages to be funny in the face of, and in response to, a tragic or hopeless situation.
Wikipedia
Gallows humor is humor about very unpleasant, serious, or painful circumstances. Any humor that treats serious matters, such as death, war, disease, and crime, in a light, silly or satirical fashion is considered gallows humor. Gallows humor has been described as a witticism in response to a hopeless situation. It arises from stressful, traumatic, or life-threatening situations, often in circumstances such that death is perceived as impending and unavoidable.
Usage examples of "gallows humor".
As could, apparently, any hope of anyone taking a vacation, which was why Nasi tried to make a moment or two, now and then, for the slightly oblique gallows humor he liked and that Mike was getting a taste for.