Practically every writer I know, and most of them are really very nice people, will tell you that they love writing villains.
An expert would probably have theories about it, but all I can say is that it is extremely satisfying to let your imagination free to be nasty. The term villain can be a broad one, from a bossy mother in law to a serial killer and everything in between. It is still fun to write. Should I really be saying that? Fun?
Thinking about my own writing, I suspect I get something from knowing that evil will eventually get its 'reward', because I am the one manipulating the plot, and that is how it is going to be. I like to tie my endings up with a positive resolution, and because of that, I won't let the bad guys thrive. No ambiguity or cliff hangers. Not always true to real life, I know, but as I have said before, I write escapism, so I can decide how the order will apply.
My villains are villains, and come to a sticky end, but there is also the big issue of the hero with the Dark Past. I have a few of those, and I like them too. Guys who have walked the dark side, know all about how it works, and have turned away from it. But, of course, they bring a lot of stuff along with them ...
I've got an idea that has been a long time brewing, for a series that is sort of the reverse - good guys going over to the dark side to put right something that can't be managed any other way. That one takes a bit of thinking about, because I'm cautious about anything that looks like vigilantism. I'm still working that one through, but it will get there. That one started with a Georgian romance that I partially completed for fun, before I was accepted for publication, and I realised that the group of spies and assassins I'd created there could easily carry forward into the present day. An organisation for justice that has survived for a couple of centuries. Plenty to play with. As I said, working on that one. Hope I might have enough time to write the series from both ends. Wouldn't that be fun.