In the socio-political arena, I often view interactions between people as math equations. If women are paid $10 an hour for doing a job that men get paid $15 for doing, then we have an unbalanced equation. If they get paid the same, then we have a balanced equation (called justice).
Similarly, a military attack on another country for no just cause, resulting in the deaths of 1,000 people, is bad math. But if that country has weapons of mass destruction and a reputation for using them on civilians, then attacking that country and killing 1,000 people in order to save millions is good math. Most people would probably consider it just.
This is an obvious example of doing a bad thing (killing people) for a just (good) cause.
On the other hand can something be so overwhelmingly good/ perfect,
but implemented or enacted in such a way that it is evil?
I just read that Mao Tse Tung ordered peasants to kill sparrows, which eat edible seeds. His intentions were good; he wanted more food available for people. However, after millions of sparrows were killed, the insects the sparrows ate exploded in population, ravaging crops. Millions of people starved.
This illustrates the well known fact that things don't always go according to plan.
Or are you asking about a good "thing" that's intentionally used to do evil? One example might be vaccines.
Vaccines were originally invented as a way to promote human health. However, there are concerns about vaccines being used to sterilize people, and some worry they could even become an instrument of eugenics.
You said you want to stick to "philosophical viewpoints," so I'm not sure if the practical examples I offered are what you're looking for.