The villain has committed a crime, and the hero doesn't quite have enough evidence to expose them directly. It seems like they'd get away with it...if their ego doesn't get in the way first.
The easiest way to reveal the truth would be to get the villain themselves to confess, and that can be done with some individuals by simply driving them up the wall with insults to their intelligence--of course they could never think up such a brilliant plan, after all. Eventually the villain would get so upset that they blurt out their involvement in a fit of passion, because they're proud of what they did and they want people to know it.
Sideshow Bob, The Simpsons
During the episode Sideshow Bob Roberts, Bob runs for and is elected Mayor of Springfield, using the position to cause misery for the Simpson family, especially Lisa, but especially Bart. The kids wind up discovering that his votes were heavily stuffed with the names of the deceased and take him to court, where he denies everything. Then they try a new tact: claiming he was just a patsy and that conservative radio host Birch Barlow, the one who petitioned for Bob's release from prison, was the real mastermind. His ego thoroughly attacked, Bob then gleefully admits to voter fraud in open court and even hands the jury stapled copies of his plan for good measure.
Flintheart Glomgold, Ducktales (2017)
During the episode "The 87 Cent Solution!", Scrooge is sick and becomes increasingly unhinged in his behavior, which the triplets diagnose as "gold fever". Eventually it appears that Scrooge passes away from his illness, and a funeral is held. Then Glomgold, Scrooge's rival, bursts in for a blatant (and hilarious) showing of last disrespects: dancing gleefully, throwing money like he's in a strip club, twerking in front of the casket, and asking to be lifted onto the casket so he can dance on that, all to the tune of "All I Do Is Win".
During the eulogy, Huey explains that they considered Scrooge's theory, but it would have been impossible for this to have been anything else except gold fever, and that they'd have to be a criminal mastermind to pull it off. Glomgold, already shown to have possessed zero impulse control, immediately admits to the assembled mourners that it was all him, that he gaslit Scrooge with the use of a time-stopping device, and that he made up "gold fever" in the first place. His deception revealed, Scrooge socks Glomgold in the face, having not actually been dead, and the entire funeral was a ploy solely to expose Glomgold's lies.
Furio Tigre, Ace Attorney: Trials and Tribulations
An aggressive loan shark and violent man otherwise, he's forced onto the stand during the case "Recipe for Turnabout" to discuss the murder of Glen Elg. Yet the evidence Phoenix has is circumstantial at best; even the fake attorney's badge Tigre used to pretend to be Phoenix and intentionally bomb the defendant's case isn't permissible, and nothing concrete is proven. Then when Gumshoe provides a green plastic bottle of medicine with Tigre's fingerprints on it, Phoenix stages a quick plan of his own: claiming that the bottle contained poison. Tigre, however, laughs off the bluff and derides Phoenix as an idiot, claiming that the real poison bottle was brown and made of glass...something that was revealed in court, but Tigre had made a point of not attending the trial prior, or so he claimed. The only way he could have known this information was if he was the true killer, conclusively putting him away.