what are some phrases for "doing something evil in order to stop someone evil"

It's commonly called a necessary evil.

From Wikipedia:

A necessary evil is an evil that someone believes must be done or accepted because it is necessary to achieve a better outcome—especially because possible alternative courses of action or inaction are expected to be worse. It is the "lesser evil" in the lesser of two evils principle, which maintains that given two bad choices, the one that is least bad is the better choice.