Take, for instance, the villain gloating over the helpless victim. Why doesn't he/she just kill the helpless victim (the hero, the hero's girlfriend, the lost prince, etc) before the victim or the victim's friends can kill the villain?
Because in real life villains gloat. In my childhood, I dealt with a few bullies, and every one of them gloated over me and what they were going to do to me long enough for me to give them a blow to the solar plexus. (And yes, that worked. Those bullies did not bother me again.) Sure enough, the villain gloated, giving the intended victim time to strike. I observed the same behavior from bullies after someone else. Trap, gloat, and either the victim did nothing (and got pounded) or the victim hit the bully in mid-gloat, and got away.
Persons in power and using it badly routinely gloat over those they know they have power over. Bush43, smirking into the camera and announcing (in a gloating tone) that he didn't have to listen to any "nay-sayers" anymore. The smirks and gloats of politicians with a safe majority. Saddam Hussein, in 1990, gloating over a family in his power--fondling the child while the parents watched, as he announced his intentions for Kuwait and Saudi Arabia.
Gloating in the moment of victory (any victory) is, I'm willing to bet, one of those deep biological things. It feels good--so the gloaters do it more and more, every time they have a chance. Feeling empowered is a good feeling. And winning (anything) releases a little burst of testosterone (in men and women.)
So when a villain gloats, in a book, that's not just to give the good guys a chance to pull a miracle rescue...it's because villains actually do gloat.
And so do even the best of us, even if we try to hide it from others...and ourselves.