It's a legitimate question, especially this week--a close relative of my husband's passed away, and before that I spent three days at a conference with a close friend who is still struggling through the grief over the loss of a parent.
In the real world, there's nothing very funny about death. In fiction, the rules change. For example, poor Mary Richards:
When the death is at someone else's hands, how can it ever be funny?
Writers like Elmore Leonard use some standard gambits, such as making the victim as unlikable as an SUV parked in a Compact spot. Or, making the manner of death surprising and poetic, such as a rageaholic dying from an angry driver's pistol shot. It's hard not to laugh at surprising poetic justice, even if we're not okay with the political correctness of it all.
It also helps if the victim dies offstage, and we don't spend much time with the body or the victim's grieving family. You wouldn't want to write in six dependent children and a widow who's not provided for. That really wouldn't be funny. Unless you are Lemony Snicket or Christianna Brand, of course.
Other writers treat death and murder seriously, and save their humor for the many scenes in between. By manipulating the modulation of tone across chapters and sections of a book, you can make humor and murder seem like natural partners. After all, they're both a part of ife, aren't they?