Despite the name, the Exemplars of Evil 3.5 D&D splatbook specifically states that villains do not have to be Evil - that Non-Evil villains do exist, as one "villain archetype".
And, conversely, Champions of Valor states of Valorous Heroes that "most are Good, some are Neutral, and a rare few are evil, but recognise that some evils must be battled".
In D&D, you can have an Evil valorous hero - accepting that you can have a Neutral (or even Good, in the case of early Miko, and Gin-Jun from the O-Chul story) villain is not a stretch - D&D is not a straightforward "heroes are always Good, villains are always Evil" universe.