Philippa Foot is most known for her invention of the Trolley Problem thought experiment in the 1960s. A lesser known variation of hers is as follows:
Suppose that a judge is faced with rioters demanding that a culprit be found for a certain crime. The rioters are threatening to take bloody revenge on a particular section of the community. The real culprit being unknown, the judge sees himself as able to prevent the bloodshed from the riots only by framing some innocent person and having them executed.
These are the only two options: execute an innocent person for a crime they did not commit, or let people riot in the streets knowing there will be loss of life. If you were the judge, what would you do?
That just pushes the question further: are judges morally obligated to carry out the law no matter its morality? Can someone, because of their position, be morally obligated to carry out a law that is morally reprehensible?
It might depend on the moral ethics of whatever field the agent finds themself in.
For example, at about 18:20 of this podcast discussing the impact of continuing education about the Holocaust on medical ethics, one medical student discusses the Nuremberg trial of Nazi physician Gerbhardt. The student paraphrased his arguing, "You cannot prosecute me on the basics of ethics, only the law," and he adds, "because at that time there was no ethics, which he was right to point out." I haven't checked what laws he was specifically charged with breaking and whether they were state or international, but he was executed all the same.
There seems to me a need to balance the obligation toward the state and the individual. Going wholly to the individual could undermine the establishment's effectiveness, but going wholly to the state, as the podcast discusses, would justify physician participation in Nazi Germany's eugenics program. More than 50% of physicians joined the Nazi party, and they killed 300,000 people in hospitals, not camps. While there are examples of physicians who hid and protected Jews and other targeted groups, I can't tell at the moment whether that was the norm.