When I talk about "ends justify the means", I am talking about situations in which being perfectly morally good isn't going to bring actual good results, if not, make the situation worse. A good example would be how a government handles foreign politics. If the gov were to open its borders because the immigrants are poor and need help, it sounds morally good on paper, but only ends up making things worse for its citizens and would put the economy in shambles. If the gov were to take a more ultranationalist tribalist approach and exterminate outsiders for their nation's well-being, on paper it sounds morally evil, but in actuality it's natural and brings a good outcome to their peoples.
At the end of the day, it's not a matter of what is good or evil, but a matter of what's right or wrong. That's why there's a big discussion of morality in philosophy. Figuring out what is good or evil is a piece of cake, figuring out what is right or wrong however requires deep thought.