This was bothering me for a real long time till it hit me hard. Mood Whiplash. While more of a TvTropes term than anything, I used to use the word a lot to describe basically the same thing as a lot these other answers. In the Tropes context, it's when a scene with a certain emotion that you've accepted and adapted to in order to immerse suddenly 180s into a different or reverse emotion.
When you are watching a happy-go-lucky innocent scene and someone pulls out a gun and shoots someone, that's Mood Whiplash. YouTube originals like Happy Tree Friends, Don't Hug Me I'm Scared and Cupcakes absolutely milk this trope for all it's worth. If you go have to laugh to shake off a tragedy, and feel the dissonance you feel from that, you just felt Mood Whiplash.