Oh hm!! so this sounds less like Voltron-type goofy moments and more like... an over-the-top tone? Like, this is maybe a weird comparison, but a lot of elements of Invader Zim were this way -- the policies of the school were over-the-top and absurdly tyrannical, the idea that no human except a conspiracy theorist would ever notice something was wrong with Zim is completely implausible, etc, but we accepted all those things because of that was the general tone of the show -- that's how the world works here, don't question it!
I don't think you can whiplash between an entirely over-the-top tone and a fully serious tone in the same story elements... but I think you can have both elements in a story. Cucumber Quest had the heroes summon a Limbo Dimension to challenge the giant squid boss to a Limbo competition, but still manages to make you feel genuinely worried and sad when the main character and his sister find their relationship strained. But the world of Cucumber Quest doesn't "change tone" -- the characters are always themselves, whether the scene is funny or serious, and always react to this strange, goofy world in ways that make sense with their personalities, so we are able to invest in them and believe in them as real people and take their feelings seriously even when silly things are happening.
The Welcome to Night Vale podcast is another example of a story that manages to take its strangely over-the-top world seriously -- despite the local radio host cheerfully encouraging everyone to remember to enter the mandatory get-eaten-by-wolves lottery, we're still invested in said radio host's romantic troubles and worried about the town of Night Vale when it's overtaken by an evil corporation. The atrocities of Night Vale were always flippant and light-hearted and never felt dangerous to characters we cared about, while the atrocities of Strexcorp felt ominous and threatening towards characters that mattered to us, and so we accepted Strex as a genuine, serious threat.
On the other hand, I think it would've been very hard to get us to take Invader Zim seriously, because the characters are over-the-top; Zim's reaction to things is funny and absurd, and trying to get us to feel for him as a real person is gonna seem disingenuous. If you want to have troublesome students get dragged off in a straightjacket as a darkly funny moment, it's going to feel like a weird retcon if you then try to get us to see this same practice as serious and genuinely cruel. So, I'd say you can absolutely have both serious and over-the-top elements in a story, but you have to be thoughtful about which elements and how you use them.