That depends.
Was the villain being possessed by some evil being of sorts, or maybe taken over by madness, then in a moment of lucidity they realized that they could no longer let the evil/madness control them, so they decided to kill themselves? That's totally a hero alright. Sacrificing themselves for the greater good and stuff.
Was the villain just plain evil and suicided when they gave up when faced with the inevitability of their defeat? That's still a villain.
Was the villain someone who was doing evil deeds for a while, then eventually realized the evil of their ways, but at this point it was too late to make amends or stop the incoming flow of horrible events with anything other than their own death, so they decided to sacrifice themselves to save the world from the very problems that they caused? That is a bit debatable, but it can be considered a hero. It's someone who saw the error in their ways and decided to do whatever it took to fix the mess that they caused, even if it meant sacrificing themselves in the process... At the very least, it would be an act of repentance, or a honorable sacrifice, but can also be seen as something heroic. It's up to each person's judgement at this point.