The novel Nuklear Age by 8-Bit Theater author Brian Clevinger plays with this trope, mirroring the development of comics as a medium. It starts out over-the-top and cheesy, quickly becomes over-the-top and genuinely entertaining, but, near the ending, it becomes over-the-top yet heart-wrenching.
Joseph Heller's Catch-22 uses this trope brilliantly. From the beginning it depicts a hopeless and bleak world that the central character wants nothing more than to escape from, but as the book progresses it starts using the same things it played for laughs early on to a much more devastating and serious effect, such as the absurd and tongue-in-cheek importance of the mess hall officer leading to a few riots, multiple missing parachutes and a tragic bombing, all for the sake of manipulating cotton markets.
The Discworld series starts with The Colour of Magic: a raft of tropes, puns and SFX. Serious themes appear in later books, perhaps starting with Death in Reaper Man. A milestone in characterization is Vimes, the fallen idealist of Guards! Guards!!. That said, it has remained comedic, albeit slightly more "realistically"; the author has said that the series has "grown up", and that, for instance, nowadays he'd never be able to just burn down the city for a cheap laugh like in the first book — though he still sees the humor in referencing such times:
The rumor spread through Ankh-Morpork like wildfire — which had spread through Ankh-Morpork quite often since its inhabitants had learned the phrase "fire insurance".
The transition here is rather similar to the Trope Namer in that the first book, and at least most of the second, were clearly intended to be a wacky parody of standard fantasy to the extent it's often possible to tell specifically which author is being parodied (for example, the bizarre punctuation in the names of the dragon riders). The parody aspect gradually faded to the point that most of the newer novels are more or less standard fantasy with comedic elements rather than comedy with fantasy elements. (Although "standard" might not be the right term for a fantasy novel about renovating the postal system...)
The Hobbit was written for children and adults. It starts off pretty fun and silly, but becomes more solemn by the end. The Lord of the Rings, which was welded into the same world after the fact, was written for a more adult audience and is much darker than The Hobbit. This may be due to the fact that Tolkien incorporated The Silmarillion into the canon of The Hobbit and The Lord of the Rings in the middle of his writing, resulting in the series becoming more epic in scale and tone (case in point: The Lord of the Rings was originally intended to be shorter than The Hobbit.)
Inkheart gets pretty damn depressing and extremely violent. In the second two books of the trilogy, which take place in the Inkworld, it turns out the place isn't the wondrous fantasy world it appears to be. The villains in these novels make Capricorn seem like a harmless bully by comparison, and even the heroes all seem to have prominent dark sides.
The Fablehaven series takes a fairly dramatic turn for the, uh, dramatic after the first book. The first book has a light-hearted cover, an only-somewhat-threatening villain, and while there are certainly scary, tense, and at least one bona fide disturbing moment, there's a lot of comedy and sheer excitement it in at the same time. (It's got scenes like milking a giant cow and giving a troll a foot massage.) The second book gets a bit creepier, as it introduces just how unsafe the magical world is... and the third and fourth books are just out-and-out scary and disturbing. Up to and including a horrifying subversion of Strangled by the Red String. So much for the Official Couple...
The Warrior Cats series is normally very serious, but the third series starts off with one of the most lighthearted and optimistic books in the series, and then gradually became more and more dark until it ended with one of the most dark and depressing books in the whole series. Since the third series was mostly character driven, this was likely done to show the Three's loss of innocence and more mature outlook on their responsibilities, much like the Harry Potter example above.
The Book of Fred began as a sitcom-esque story when a girl, Mary Fred, having raised in a wacky cult (that, among other things, valued the color brown, fish, and the holy name of Fred) was put into a foster-care program and tried to adjust to normal life. By the end, the book had tackled rape, drugs, comas, and other crises—completely seriously.
The Dresden Files, sort of. The first book, Storm Front, certainly had its dark elements; murder, drug addiction, etc. were all involved in the story, but there was a lighter background and Harry seemed to actually enjoy his life, Perpetual Poverty aside. The books have trended steadily darker since, particularly when the Wham Episodes of Grave Peril (Susan is half-turned by vampires, Harry flips out and starts a war), Dead Beat (most of the White Council is annihilated within two days), and Changes (which can basically be summed up as "From Bad to Worse").
In book one, Harry fends off a vampire with a handkerchief full of sunlight. By book six, he can't do that any more, because it turns out you need to be happy to fold sunlight into a hankie.
Turn Coat through Cold Days are where it sets in to a noticeable degree. At the start of Turn Coat Morgan is accused of treason against the White Council. By the end of Cold Days Morgan is dead, Harry has done things he swore never to do, including becoming the Winter Knight, killing his former lover Susan, and causing Molly to go insane and Harry is the only thing standing between a prison complex where one of the strongest non-affiliated monsters he has ever fought is in minimum security and Chicago.
P.N. Elrod's Vampire Files series started out as a subversion of vampire wangst, in which Jack Fleming's undead state was treated more like a superhero's abilities and weaknesses than like an occult curse. Basically, he was a detective who could turn invisible and walk through walls, the sort who'd literally use his powers to play pranks on gangsters. But things changed as the villains got nastier: Jack was tortured, his Horror Hunger intensified, his mortal best friend's horrific past was revealed, and the erstwhile subversion of Wangst was nearly Driven to Suicide. While the latest book suggests Elrod has reversed course, pulling Fleming back from the brink, for a while there things had gotten so grim that Lifeblood, the second book in which Jack argues in defense of his Vegetarian Vampire nature, had almost become an in-universe "Funny Aneurysm" Moment.
Moby-Dick starts of in a light-hearted style, as if embarking on a jolly romp around the Seven Seas in search of diversion and adventure. Then the obsession cuts in.
Books 7-9 of the Undead and ... series have taken a turn for the dark, with unexpected deaths of supporting characters, increasing evil behavior of Laura, who is the Antichrist and the main character's half-sister, and various depressing tidbits of info gleaned from time traveling 1000 years into the future, where things go From Bad To Worse. Word of God is that this change is deliberate, and even the cover art for the three books changed from it's original "chicks who love shoes & pink" theme to more of a "noir thriller" look.
T. H. White's The Once and Future King starts off very light and playful, with Arthur as a child going on magical adventures under Merlin's tutelage. Then he pulls the sword from the stone and it goes downhill from there. White actually went back and rewrote the first novel to be more serious, so that the books could be read in order without experiencing Mood Whiplash.
Flinx in Flux marks the transition of the Humanx Commonwealth series from a light-hearted and mainly episodic Space Opera to a battle for the fate of the entire galaxy when it introduces the Great Evil. It also marks Flinx's transition to full maturity by introducing his ongoing Love Interest, Clarity Held.
This is visible in Septimus Heap where the first book start out with a rather cheery atmosphere but progressively darken until the very existence of the Castle is threatened in Darke.
Michael Grant's Gone book series has become this, Gone started out fairly light hearted, sure a few kids died but there was still a cherry end party, by the time plague's climax hits, Despair Event Horizon is almost reached. At least Fear brightens up, slightly, although Light is by far the darkest one.
Animorphs started out fairly dark, but it got so much worse as the series went on, until the final arc which was really more suited to a young adult series than to something kids would read.
Also, all of the prequel stories The Andalite Chronicles, The Hork-Bajir Chronicles, and The Ellimist Chronicles. Basic plot summary: main character is living their life, encounters aliens, technology, and powers beyond their comprehension, and ends up trapped in massive war with no clear end in sight, alone and forever alienated from the rest of their species (if there even is a "rest of the species" ).
While with the The Hork-Bajir Chronicles the end of the story is a Foregone Conclusion, The Andalite Chronicles actually starts out pretty light, until one character is trapped in the form of a giant cannibalistic centipede, another is trapped inside his own head with a Puppeteer Parasite pulling the strings, and the protagonist abandons his species for a new one, only to be pulled away from his family there and back into war.
Harry Potter had some dark material in its first few books, but the child characters always managed to escape from the worst perils, and Rowling kept the darkest material in the backstory or just avoided discussing it in detail. But from the moment when Voldemort says "Kill the spare" in Book Four, all of that changes. And from that moment on, grief, mortality, and survivor guilt become constant themes of the books.
Bridge to Terabithia started out as a light hearted story about friendship between the two protagonists Jess and Leslie, and their adventure's in their magical kingdom. Then Leslie dies, and then it becomes Jess grieving for his friend and coming to terms with her death.