a necessary evil

A necessary evil is a term used for something that way be evil, unacceptable or deemed bad but is actually necessary for one reason or another. It may literally be necessary in order to commit an evil or illegal act, or it may just be the way someone rationalizes bad behavior in saying they admit the behavior was evil in a sense, but it was also necessary.