First off, I know alignments are something that makes it easy to slip into "opinion-based" territory.
I assume everybody has a gut-feeling that makes it easy to discern good and evil.
But what makes something we perceive as "evil" act an "evil" act regarding the rules?
I want/need to know how this is supposed to work mostly because thanks to abilities like "divine sense" this can make a huge difference regarding the first impression of important/powerful NPCs.
I'm gonna describe a scenario and why it could work either way:
King Ironfist the hardly empathic rules, as his name implies, with an iron fist. Opposition, dissent, even comparatively minor crimes are squashed with immediate and disproportianate force and any other means deemed necessary.
Despite this first impression though, his taxes are sensible, state subsidiaries support the churches in caring for the poor and needy, everyone willing to bother can get a basic education for free, trade within and outside the borders flourishes and said borders are secure.
In short: His citizens are safe, educated and cared for.
The king is content: His sacred duty to protect and care for his subjects could hardly be fulfilled any better.
So, what is his alignment?
Is it lawful? He is, after all, the king. Using spies and assassins and having a... well equipped and staffed dungeon is kind of a basic necessity in his craft.
Is it neutral? He is using both his official authority as the king and an assortment of shadier means. Out of necessity, not personal preference.
Is it chaotic? He is using any means after all. He needs results and doesn't value codes of honor or other social contracts that could be obstacles to getting them.
Is he good? All his actions, his whole being is dedicated to providing for his subjects.
Is he neutral? The evil deeds done on his command are kinda offset by the good wrought with them.
Is he evil? At the end of it, all he does is consolidate his power on himself and use it as he sees fit. Also good can never stem from evil deeds, no matter how well-meant they were.
As you can see, I can imagine him being somewhere along the whole spectrum.
He will propably perceive himself as lawful (fulfilling his duty as king) good (providing as good as he can for his subjects).
Objectively his position would be propably morally neutral - the good and evil balance themselves out. The order/chaos alignment would depend on the balance between his use of official authority and inofficial dark deals.
If the subjective assessment of his subjects is what matters most he might even be lawful evil! After all even real people tend to take everything good that happens to them for granted while being dismayed and holding grudges for everything bad.
Or chaotic evil if they notice his moves in the shadows: Our king does whatever he wants and clings to power by any means necessary.
This question was partly inspired by "good is not nice".
As far as I am aware the D&D alignment system never had any significant changes (which is why I didn't put it in the first place), so if I am wrong in that regard I'd be happy to extend my knowledge.