It happened gradually as I wrote. My heroine's best buddy started acting a little funny. He began making some choices that were harmful to her. I watched in horror as he deliberately sabotaged something that she was doing. I stepped back to read what I had written.
How did he know to do that? How could he be such an evil jerk after everything that they had been through together? Slowly it dawned on me that the very evil I had written into him had come from inside my head. Once I observed this happening in my own writing, I revisited some familiar passages with a new eye.
If Robin Cook wanted a character in Shock to die from a hemorrhage during an egg extraction, then he had to convincingly portray the behavior of a doctor who would allow a patient bleed to death while a lucrative surgery proceeded. The author didn't have to experience this himself as a physician. He could take some ideas and feelings from his practice as a doctor and let his imagination extrapolate them into something new and criminal.
As I am learning to write fiction, I get flashes of insight and potential behavioral choices that come from the supervillain inside my own head. I don't intend to act on these impulses or ideas. But my imagination is capable of writing about these criminal choices. This is both scary and intriguing to me. It signifies a deep understanding of evil that comes from my imagination, not my experience.
When writers tell stories, they relive and rehash and even suggest horribly unpleasant incidents. Some of them choose to leave readers there in the negative. Some are neutral and pragmatic. Some of them pull readers back out to a triumphant good over evil ending.
So far in my own writing, my subconscious pushes for my protagonist to always leave my supervillain soundly defeated.