Pain, in itself, is an evil ... even though it can lead to goods.
Before effective anesthetics, setting a broken collar bone could be incredibly painful. Believe me, I know. But NOT setting it would be ... terrible.
So, the evil pain of the setting was, ceteris paribus, necessary. -> necessary evil.
Part of the confusion can be the blurring of specifically moral evil with other sorts of evil. The pain, an evil in itself, is not moral. The act of promoting healing is morally good.
...
In war, collateral damage, if it's truly not the object of an action, is an evil but not, in itself, of moral evil. If the war is otherwise just and conducted justly, the evil of collateral damage is understood as an unintended concomitant ... a necessary evil.
I hope that's neither pompous not fatuous.
Your post makes me think of all the evil that Jesus went through to redeem us from our sins.