Mr. Writer, you don’t actually believe that the end does not justify the means
“The end does not justify the means” is one of those cliché moral lessons that you get in media, right next to “believe in yourself” and “the power of friendship”. It comes into play whenever a writer feels the need to pontify abut what an enlighten person they are. That’s why is very annoying that seemly none of the writers spreading this lesson actually believe in it one bit. This is noticeable because their objections fall in one of a few very predictable categories:
The mean is ineffective: This is where bits like “I am going to achieve my great cause by burning down an orphanage ” fall. It’s pretty obvious that whatever evil thing they were doing to get to their goal wasn’t even going to achieve what they wanted. It may even be completely counterproductive by alienating potential allies. This is not a moral objection to the villain's actions, it’s an intellectual one, they are literally just stupid.
The end is evil: Here we have the villains who play the “my people/myself were wronged in some way so I am just going to kill/enslave the wrongdoers in revenge”. Writers will try to play this as an example of The end does not justify the means, but the objection presented is simply that the end itself is undesirable, it tells you nothing about whether the mean would be justified or not if the end was a good one.
The hero just solves it: Here we have a case where the villain is willing to do horrible things in order to achieve something good but the protagonist manages to do it anyway without doing any of those horrible things. This can happen if the solution used by the hero was an obvious one, in that case the villain just looks like an idiot who couldn’t see the obvious (again, intellectual objection, not a moral one). But it can also happen if the solution used by the hero was a convoluted one that had little chance of succeeding. In that case the messages feels even more dishonest, of course the hero can easily claim moral superiority when the universe itself conspires to make him achieve his ends without getting his hands dirty.
So how would you actually present the The end does not justify the means bit without sounding dishonest? I can image just two ways:
The villain succeeds in in their goal. They actually achieve the clearly good thing they were hoping for and create more good than the harm they caused by their means. The narrative must find a way to present this as a bad thing.
The villain fails at their goals by the hero’s intervention. It’s made clear that now the greater good will not be achieved and that this is due our good guys’ actions. The narrative must find a way to present this as a good thing.
The fact that both of these approaches are extremely uncommon should illustrate how rare is to find a writer who truly believes that the end does not justify the means, despite how many of them will claim otherwise.