Humor is tough because it's so subjective, but also, a lot goes into making a joke or gag land. There has to be build up to the punchline--a set up that gives context. The joke has to be consistent with the character, unless the joke is that it's something out of character, and then you have to make that clear. It also has to fit the situation or it could break the tension of say, a fight scene, or an emotional moment. You also have to use the type of humor that best fits the story you're trying to tell.
So, keeping all that in mind, let's look at MCU humor since you mentioned it earlier. We'll start with Age of Ultron because Whedon is a hack and the humor in that wasn't good. He constantly writes this back and forth between characters in situations when the focus shouldn't be on quips and one-liners effectively draining the tension away from big fight scenes. He did this in Justice League too, to the same effect.
Compare that with how humor is handled in a more grounded MCU movie, like Winter Soldier. One of my favorite exchanges is at the start, with Sam and Steve. The jokes have a good setup; Steve repeatedly lapping Sam. It's all grounded humor that fits the characters, just a bit of friendly banter. And it also leads towards some character building with them bonding a bit over their shared experience as war veterans. We also get some fun bits between Natasha and Steve, and note that, while they do joke around during dangerous situations, they do it in moments of quiet, when they're not in immediate danger--slow moments between a build up and resolution of tense situations.
Guardians of the Galaxy is one of my favorite series and has a lot of silly humor, but it works because the characters are established as idiots. Gamora and Nebula are usually the more serious ones and you can see that in the way humorous moments are built in a way where they usually express frustration with whatever Quill, Drax and Rocket say/do. The humor builds on and expands on the relationships between these characters, and while it's also used during moments of danger and high tension, it works because we've established a more chaotic and improvisational nature to the characters and their style of doing things, like the dance-off at the end of the first movie. Quill uses the absurdity of the situation to distract Ronan. It's in character with who Quill is, because he's smart, can come up with a plan on the fly, but he's also a bit of an idiot so he's not gonna solve it with some Supergenius move. He's going to throw people off and use that to his advantage.
The point is that humor needs to fit the character, situation and tone of story or it will feel jarring to the audience. Look at, say, The Simpsons. The old shows are hilarious, but take a joke from it and put it into another movie/show. It probably won't work because the style of humor doesn't fit.
I'd suggest you figure out who your characters are, what you want your story to feel like, and what style of humor would best fit. Keep in mind whether a joke adds to the story or detracts from it, like whether it breaks the tension or ruins an emotional scene or builds it up.