The most widely-discussed theories of right-action in recent anglophone philosophy, Kantianism and Utilitarianism, each have ways of allowing that actions that would otherwise be wrong can be right under certain circumstances. Both understand such an action as right when it's done for the right reason (and no longer wrong).
Kantians have long discussed the “murderer at the door” scenario, where a murderer asks you where someone you know is, because the murderer wants to kill him/her. Kant brought up this example in Groundwork for the Metaphysics of Morals. Recent Kantians have argued that while it is usually wrong to lie, it is morally right to lie in this case. Philosopher Christine Korsgaard has a great discussion of this in her essay “The Right to Lie: Kant on Dealing with Evil."
Utilitarians, similarly, would argue that it's possible for actions that, performed in isolation, would be harmful to be good, if they produce the most overall happiness. The second chapter of John Stuart Mill's Utilitarianism discusses this point.
This forum is not the best place to find literary/fictional references, but one fun example I think of is Jack London's The Assassination Bureau, Ltd. which is about a group of professors who decide that it's okay to murder people who are harmful to society, and argue with each other about that.