An effective way to make a joke in a dialogue is to make the punch line protrude in some way from the rest of the text while being followed and preceded by normal text.
It is important to clarify that the dialogue and the situation that revolves around the line of dialogue must be in resonance with one another.
You do not play clown jokes in the middle of a war or at a funeral.
In itself, you have to remember that your characters are real people in your story, they have fears and aspirations and react in the same way that you or me (in their place) would, they are not robots, nor masters of comedy.
If you must put jokes, you should not seek to be funny if they do not agree with the situation or the character.
Batman does not make jokes
The joker does, but his jokes and jesters are not funny, they are scary.
Spider-Man makes jokes of his cituacion highlighting how ridiculous what is happening right now and how it somehow will end up in his favor, as if it were the most trivial thing in the world.
Rule No. 1 of commedy: The funny thing happens when something that was not what we expected happens.
Do you imagine a situation somewhat intense and then solve or mark it in some unexpectedly way to create comedy (not in a spectacular way bit not the less).
This is all very generic the best way is to write lots of variation of you scene and then choice 1 that is the most funny afterwars.
And remember the rule of comedy No 3: Comedy comes in 3, but that´s a story for another day.
Cheers mate!, and good luck.