Hermione constantly saves the day in Harry Potter because she was the only one paying attention in class when the relevant magic was discussed.
This sort of thing is even done across books. In the fourth book, Dumbledore casually mentions a room filled with chamber pots that he found when he desperately needed a bathroom, and then was unable to ever find again. In book 5, the room is formally introduced as the Room of Requirement, and ends up being an integral part of the story in every remaining book in the series.
And in the very first book, Snape quizzes Harry, and one of the questions is about bezoars. In book six, it's used to save Ron's life, although Harry re-learns about it from Snape in a roundabout way.
Divination class is very much a Chekhov's Classroom. Most of the class believes that it's ridiculous fakery, but looking at the predictions made with knowledge of how the books turn out reveals a surprising amount of Foreshadowing.
In Dan Brown's Angels & Demons, an early discussion of how well an Improvised Parachute can work saves Robert Langdon's life when he jumps from an exploded helicopter with a window cover. This is also lampshaded at the time the discussion takes place.
Modern pulp author Matthew Reilly uses this to a ridiculous degree. Two examples:
In Temple, there's a throwaway sentence from the protagonist about how he'll need to change his PIN number after reading a story in the paper about how most people use their birth dates as pass codes. Guess how he defuses the superweapon his brother worked on? Guess again, it wasn't his birthday. But that example was used as a starting point. His brother always used Elvis' army serial number as his PIN. The Nazi scientist used his supposed date of execution.
In Area 7, a precocious youth found in the middle of a government base delivers a buttload of the kind of trivia kids that age accumulate and share at any opportunity, including how komodo dragons are sensitive to changes in the Earth's magnetic field. So there's a scene where the main character has to fight off komodo dragons in a watery pit with his magnetic grappling hook.
Arthur: You know, it's times like this I wish I'd listened to my mother. Ford: Why, what did she say? Arthur: I don't know, I wasn't listening!
In the Strange Matter book Knightmare, the protagonist remembers a comic his friend told him about in where crossbow being the only weapon to pierce the bad guy's armor. He later uses a crossbow to pierce the evil knight's armor and kill him.
An opening scene of Galaxy of Fear: Eaten Alive has a zoology lesson mentioning how the fearsome rancor, which usually kills anything it sees... except for the tiny gibbit birds which venture into its mouth to clean its teeth. The characters end up on the planet D'vouran, which is a carnivorous entity that will slowly eat any beings on its surface except for the native Enzeen, who make people want to stay there.
In The Nightmare Machine, Lando teaches Zak how to play cards, and that "A good rule to follow is that if the other guy is acting normal under unusual circumstances, you can bet he's bluffing." Ultimately that's how he knows he's in an illusion later.
The Doomsday Ship has Tash finding a bit of Jedi lore about how sometimes it's better to take "action through inaction", or that waiting is sometimes a valid response. She shows it to her brother. After that, Zak finds his uncle playing dejarik on the computer and taking his time despite an icon on the screen flashing "YOUR MOVE". Uncle Hoole says sometimes the computer has to wait, he's strategizing. This is important later.
The Hunger Games: Peeta explains to Katniss how each district has a distinctive recipe for bread, which later allows her to recognize that the gift she receives after memorializing Rue must have come from Rue's own people. It comes back inCatching Fire, where Finnick is mentioned multiple times to count the bread they receive as gifts rather obsessively. It turns out that he was in on District 13's plan to break the tributes out, and bread was a signal. The district the bread came from indicated the day they'd be rescued, the number of rolls the hour.
In one of the American Girl solve-it-yourself mystery books, Molly and her English houseguest Emily discuss the differences between American and British English, including how the word "queue" (pronounced the same way as "cue") means "line" in England. Later Emily ends up performing awkwardly in a school show and ends up about ready to cry when the teacher scolds her; Molly jumps in and explains that when the teacher told Emily to wait for her cue to go on stage, Emily looked for a line that didn't exist and as such, her performance got thrown off.