In Harry Potter and the Philosopher's Stone, we have an adorable, Cinderella-like little boy exploring the wonderful world of magical, colorful wizards. Then, he sees his dead parents, he's almost killed by a mysterious blood-drinking figure, and he's confronted by a trusted teacher with the Big Bad growing out of his head.
Harry Potter and the Goblet of Fire, definitely. We have this awesome contest, with romance and rivalry, fun and games. and then we see two characters get shipped off to a graveyard, one killed for having tagged along in a ghastly manner, Harry tied to a gravestone, his blood taken from him, Voldemort coming back, him taunting him, ready to kill Harry, Cedric and his parents coming back out of Voldy's wand, and a Death Eater impersonating as a teacher all year, who also tried to kill Harry.
The contest is always quite serious; there have previously been plenty of casualties in the regular tasks of the Triwizard Tournament before. It was originally discontinued because the death toll got too high.
Done both hilariously and heartbreakingly in Harry Potter And The Order Of The Phoenix. Whilst on the ward for mentally damaged permanent residents of St Mungo's hospital, we see post- memory loss Gilderoy Lockheart, who is just as mind-numbingly stupid and arrogant as he was in CoS... And then straight afterwards the absolutely devastating fate of Neville's parents is shown. Cut back to Lockheart talking about how he can do joined up handwriting.
The Baby-Sitters Club series - Claudia and the Terrible Truth, where the Very Special Episode-esque main plot (the girls finding out that two of their new charges are being abused by their father) is interspersed with the sitters helping kids preparing for a St. Patrick's Day parade.
The Hunger Games trilogy is loaded with these moments- they'll take you from heartwarming happiness, or seeing the characters laugh for the first time in weeks directly to horrific death and much despair.
Macbeth has a classic case. As Lady Macbeth goes off to kill the king, a scene that could be very disturbing to Elizabethan audiences, so Shakespeare followed it by a comic scene with the castle porter answering the door.
The Kalevala is Finland's national epic, compiled in the mid-19th century from oral traditions that in turn date all over the previous centuries/millennia. At one point, it features the Eternal Sage, in search of words of power, descending into the Netherworld until he stands before its black river and meets the daughter of Death itself. She's short and fat, and washing clothes in Finnish!Styx. Yeah, that's right. At least to a modern audience, the prehistoric sagas subvert themselves when they start getting too serious.
Many of the short stories of Sholom Aleichem have a weird combination of humor and depressing reality. For example, in the short story Two Dead Men, we leave two of the main characters, one of which is so drunk he can't even remember the holiday it is, clumsily trying to get themselves out of the mud and look at his wife, who is worried her alcoholic husband's going to be found dead in a ditch.
The Discworld series is usually billed as 'uproariously hilarious' or the like, and in many places it is. However, there are many parts that range from dramatic and moving to outright horror—for instance, the torture rooms of the Particulars in Night Watch.
Pratchett also manages to do utterly hilarious and tear-jerkingly dramatic at the exact same moment. I'll only say: "THAT! IS! NOT! MY! COW!"
In Jingo, Vimes's plotline is juxtaposed with scenes of Vetinari, Colon and Nobby in Al-Khali. What Vetinari is actually trying to achieve is in fact very serious (and is the same as what Vimes is trying to achieve, i.e. stopping the war) but because he has Colon and Nobby with him, the scenes are much funnier than Vimes's, who spends most of it wondering how he'll ever get out alive. Oh, and listening to a Dis-organizer literally telling him "Things to do todaytodaytoday: Die!"
The Time Traveler's Wife has moments like this. Towards the end of the book, there are some fairly depressing scenes, such as Henry discovering he will die in several years, or Charisse acknowledging Gomez's feeling towards Clare. This is followed by a fairly comical scene where Henry travels a few months into the future and ends up locked inside the library, which forces him to reveal his time traveling nature to the entire library staff. A few pages later, Henry almost freezes to death in another time traveling incident, and ends up losing his feet. And lets not mention his death scenes....
Fools Crow by Richard Welch has a very strange ending: in the penultimate chapter, the main character Fools Crow (A Pikuni Blackfoot) finds a village of another band of Pikunis that had been slaughtered by white men. He reflects on the essential hopelessness of the Pikunis' situation with the white men. Previous chapters dealt with the ravaging of the Pikunis by smallpox. In the last chapter, Fools Crow and his tribe celebrate joyously a Blackfoot ceremony, the buffalo return, and everything is put back in equilibrium. Huh?
George Pelecanos' novel King Suckerman does a meta twist on Mood Whiplash: The book starts out as a light-hearted take on '70s exploitation films with a strong hint of Quentin Tarantino, with pop-culture riffs and catchphrase-spouting badass drug dealers and ex-cons. About halfway in, some of the characters go see a hotly anticipated blaxploitation flick (the titular King Suckerman) which abruptly ends on a depressing note. From that point on, the novel itself takes on a darker, more menacing shift of its own; the previously cool-seeming criminal characters turn out to be rather monstrously evil.
T. H. White's The Once and Future King started as a light hearted parody of Arthurian Legends, with anachronism, Merlin as a bumbling magician, Arthur turned into various animals, and Pellinore's ineffectual quest for the Questing Beast. Slowly each following chapter got less and less humor and got darker and darker, until the tragic last chapter that ended just before King Arthur's fight against his son Mordred as he reminisces over the good old days.
The Reynard Cycle: The entire series hinges around this. Many readers are cheering for Reynard by the end of the first book. By the end of the third . . .
Mark Twain's works often suffer from this, the most notable example occurring in The Adventures of Huckleberry Finn where we are treated to a humorous drunk, a cold blooded murder, an attempted lynching, and then a circus, all literally in the same chapter.
A Connecticut Yankee In King Arthurs Court is particularly egregious, since the mood whiplash effect arguably results in an Out-of-Genre Experience. The book goes from a scene where Sandy actually thinks a pig farmer is really a bunch of 12 foot tall ogres and the pigs are captive princesses (which is a laugh out loud hilarious scene) to a gut wrenching description of slavery. It feels like going from a Discworld type absurdist satire to high drama.
Codex Alera often manages this by juxtaposing a Crowning Moment of Funny with a serious scene. The most spectacular example was at the beginning of Princeps' Fury, when we're treated to some hilarious bickering between a couple of soldiers. Then they're attacked by the Vord, and one is ripped into little bits while the other has to be Mercy Killed by Ehren.
Bridge to Terabithia: The book (and by extension, the movie) starts out relatively lighthearted and without drastic conflict...and ends up becoming completely tragic and melancholic following the revealing of Leslie's death. The same pattern can be seen in similar works, such as A Taste of Blackberries.
Catch-22 practically runs on this trope. The author seems to have taken a particular liking to ending chapters by revealing critical bits of information that cause the reader to re-evaluate the events of the chapter, which had up till then been Played for Laughs, in a much more sinister light.
Book five of Virgil's Aeneid. The first half describes the funeral games for Anchises, in a generally light-hearted and sometimes humourous manner, ending with a running race in which the contestants start tripping each other up and get into an argument about who really won, which Aeneas cheerfully settles by bringing out extra prizes for those who feel cheated. He then gets the news the Trojan woman have become so disillusioned and tired of the constant travelling that they have set fire to his fleet, leading to his emotional low point - even his own people have now turned against him - and the realisation that he must now descend into the world of the dead.
Kids' novel Jennifer the Jerk is Missing. Starts out very suspenseful, with an 8 year old boy who has a reputation for telling tall tales and being a brat, trying his best to convince his 13 year old babysitter that he did in fact witness the kidnapping of his 8 year old classmate, bratty Jennifer "the Jerk". Played totally for suspense for the first half of the story, but things start to get silly when Jennifer is encountered. Bound to a chair and gagged, she actually lets out a muffled bratty "ha ha" under her gag when her rescuers mess up, and things just mostly get sillier from there. One of the kidnappers even merely pretends to have a gun by pointing his finger through his pocket (and Jennifer can even tell). Totally shoots the suspense in the first half of the book to pieces. (Then later, it starts taking itself seriously again)
Yoda: Dark Rendezvous alternates a much sillier-than-standard Master Yoda with reminders that a war is going on. A set of undercover Jedi suffering through transit on a ship belonging to a cut rate cruise line, having to deal with things like an overexcited fire alarm system and a mazelike ship structure, turns heart-breakingly tragic when Asajj Ventress comes in and starts trying to kill the main cast. And anyone between her and them.
Aaron Allston's run in the X-Wing Series can tend towards this at times, but it helps that he does use transitional devices, and much of the silly is a deliberate in-universe attempt to raise morale.
In The Giver, there is a nice scene where Jonas watched his father give the smaller of infant twin brothers a check-up. It's so nice and lovely, and... Wait, that's that needle? What do you mean "can't have two identical people running around?" WHAT DO YOU MEAN "THE VEINS IN YOUR ARM ARE TOO TEENY-WEENY?!?!"
The Watsons Go to Birmingham—1963 starts out as a light-hearted family comedy told from the perspective of a boy living in Michigan. However, in the last couple of chapters the boy has a traumatizing brush with death when he nearly drowns in a whirlpool, and the family's titular road trip to Birmingham ends with them witnessing the infamous 1963 church bombing, which makes them fear that their youngest daughter has been killed. Fortunately, she's okay.
MASH Goes to Maine is mostly about a charmingly eccentric cast cheerfully bending the rules and beating the odds. Then you get to the story-within-the-story "The Sound Of The Moose"...
In Half of a Yellow Sun by Chimamanda Ngozi Adichie, a happy wedding is interrupted by an aerial attack.
Rudyard Kipling uses it to great effect in "The Young British Soldier": set up like a drinking song, the poem starts out as a darkly humorous treatment of things like alcohol, cholera, and cheating wives. Then the last stanza hits like a punch to the gut.
When you're wounded and left on Afghanistan's plains, / And the women come out to cut up what remains / Jest roll to your rifle and blow out your brains, / And go to your Gawd like a soldier.
In-universe example in The Witcher. Geralt says of Dandelion (an accomplished bard and poet) that the latter's talent generally lies in ability to enact abrupt swings between touching lyrics and bawdy obscenity.
Transformers: Wings of Honor: Flames of Yesterday (a text story) pokes fun at the idea of gender, and the unruliness of the teams, then the Decepticons show up. This is especially noticeable with their weapons, high pressured water-guns that shoot chemicals. They shoot Metalhawk (after realizing that their guns are pump action), and he goes into crazy ramblings about colored rabbits. One shoots the head scientist with a more concentrated pressurized blast, that, coupled with her lack of armor, nicks her laser-core and kills her.
Honor Harrington pulls this twice in a single chapter. Honor's return to Grayson starts out very lighthearted, with Protector Benjamin trolling Admiral Matthews by dropping the revelation of Honor's return. This mood continues when she personally meets with Benjamin... then it shifts on one word: "Momma?" And then we're into tears of happiness as Honor is reunited with her parents, gradually shifting back into lightheartedness as Honor meets her brother and sister. Then Nimitz and Samantha are reunited... and the tone shifts suddenly to shock as they realize that Nimitz has been rendered telepathically mute.
French playwright Marcel Pagnol's childhood memories, 'My father's glory' & 'My mother's castle', definitely qualify. The two books are highly enjoyable tales of Pagnol's discovery of the countryside as a child in the 1900s, his admiration for his father, his love for his mother, his adventures with his brother and the birth of his friendship with a country boy. In the last chapters, the story goes from a joyous Summer dinner to young Marcel following a hearse and a list of all the tragedies which subsequently happened: Pagnol's mother died very young, only a few years after the events of the books, his childhood best friend was killed at barely 20 in the first world war, and his younger brother decided to stay in the countryside and died at age 30. "Thus is the life of a man. A few moments of happiness, quickly erased by unforgettable sadness."
At one point in the Relativity story "Let It Snow" (which is mostly flashbacks used to flesh out some of the main characters' backstories), Sara is reminiscing about Christmas when she was four years old. First she opened her birthday present (her birthday is two days before Christmas), then she helped her older sister bake cookies, then her father came home and beat up her mother.
In The Count of Monte Cristo, the young women Eugenie and Louise are planning their escape from the French aristocracy. It's a tense, risk-filled scene...until Eugenie swears, and the two erupt in laughter.