It's common knowledge (or used to be) that humor is a healthy coping mechanism for fear and dark/uncomfortable situations.
In other words; comical relief.