Shifting tone can work but it has to give some time to breathe and there's a few different ways to fail:
CAD's infamous miscarriage storyline became such a joke because it was so unexpected and unearned that it became funny that the creator veered the build up into pretentious drama with his wacky video game sitcom who never faces any long lasting effects. It didn't help matters that most of the focus was on the father and the mother barely figured in.
Teen Titans Go and Ultimate Spider-Man are text book examples of tone whiplash. You can also look at the movies of Michael Bay for this. Now we're silly! Now we're serious! Now we're dramatic! Now things are silly again! Now a sad moment. Why aren't you sad?
You can have varying tones in different parts of the story, but you have to give that tone time to be on stage, do its thing, fade out and we can shift into something else more gradual. Oddly enough, the original Teen Titans cartoon could get silly but also got dramatic and serious in the same story without the two drowning each other out by a sudden shift. Cowboy Bebop played with our serious heroes mired in dark pasts being stuck in odd and absurd situations, and we could get some great comedy between some really amazing action sequences just right after without it feeling too out of place.
The best way to go is treat the tone like a soundtrack. Fade out the old track, fade in the new one, and use record skips and jarring swaps sparingly.