Some of the best funny lines come when the characters in a story are in some kind of danger. About to be eaten by a dragon, about to be rolled over by a massive boulder, about to have the auditor tell them how much they really owe… all these are key points for humour. We use humour as stress release. When the tension can’t build much higher, humour is our value to let out some steam so we can think again.
Then there’s black humour, dark humour, the kind that appears to take life lightly and yet all too seriously if you look under the humourous front.
Well, the telling of jokes is an art of its own, and it always rises from some emotional threat. The best jokes are dangerous, and dangerous because they are in some way truthful. – Kurt Vonnegut
Write a scene with characters in danger then give them a smart ass line. See if you can come up with something sarcastic or just funny in it’s simplicity. Make even yourself laugh in the face of danger.