A single word or phrase for something that necessarily causes both harm and benefit?
Solution 1:
From thefreedictionary, it's a...
two-edged sword - something that offers both a good and bad consequence
Also double–edged sword (M-W) - both versions are equally common on both sides of the Atlantic.
See also it cuts both ways (it affects both sides of an issue equally).
Solution 2:
Necessary Evil — Cambridge
noun Something unpleasant that must be accepted in order to achieve a particular result
"I think he regards work as a necessary evil."
"Most Americans accept taxes as a necessary evil."
Solution 3:
That can sometimes be called a mixed blessing:
something that, although generally favorable or advantageous, has one or more unfavorable or disadvantageous features.