Tl;dr version. The so-called "ethics/law divide" is often discussed in the context of non-legal professions. Does such a divide exist in the practice of law or is it a contradiction?
The ethics of quite a number of professions acknowledge at least a theoretical possibility that breaking the law might be ethically justifiable or even necessary. The classical example is a physician practicing under an oppressive regime who is ordered to perform experimentation on political prisoners or assist in a genocide. Most medical ethicists would agree that the physician has a duty to refuse to participate regardless of whether such refusal results in civil or criminal liability attaching to the physician. An article from the perspective of medical practice is Where the law and the ethics conflict? from the joint AREC, UK Clinical Ethics Network Conference ‘Ethics in Common’. For a discussion of some potential practical examples of ethical/legal conflict and dilemmas in the practice of social work, see the article "When Ethics and the Law Collide" from Social Work Today.
At first glance, it seems that these ethical principles would not apply to the practice of law, since lawyers derive their professional competence to practice, even their reason for existence, directly from the law and the courts rather than practicing despite the presence of laws and courts potentially trying to steer them astray from the principles of their professions. That is, physicians, social workers, nurses, physical therapists, clinical psychologists, dentists, teachers, child care workers, etc. walk a fine line every day between upholding the ethical principles of their professions while at the same time remaining subject to the law and its own requirements. They have two "masters", so to speak. Lawyers have no master but the law.
Is there any precedent either way (in any jurisdiction or before any court) on whether there can or cannot possibly be an ethical/legal conflict or dilemma with respect to the practice of law? An example of such a conflict might look like:
I'm a lawyer admitted to the bar in Ruritania. A new Ruritanian statute (cite) requires all lawyers to affirmatively report to the police all clients "who have made anti-government statements or who are reasonably believed by the lawyer to have participated in an anti-government protest in the past three years" under penalty of imprisonment and fine of the lawyer, but the latest bulletin of the Standing Ethics Committee of the Bar Association of Ruritania asserts that complying with this law is unethical and that lawyers who comply will be disbarred regardless of whether the law is upheld as constitutional or not. What should I do? What can I do?
From another perspective, could there be a scenario where legal ethics permit or even require a lawyer to violate constitutional statutes, commit blatant crimes, disobey valid court orders, knowingly remain in contempt of court, disregard prevailing rules of court, insult or threaten a judge, or otherwise get "in trouble" with the law in the name of upholding legal ethics, or is adherence to the law above all else the sine qua non of legal ethics?
Bringing everything back to the beginning, do lawyers living and practicing under oppressive regimes have some ethical duty to help themselves or their clients disobey blatantly "wrong" laws? In other words, can the law itself be unethical enough that lawyers are not professionally obligated to follow it? Plenty of extreme or not-so-extreme hypotheticals can be considered. For example, suppose a law is passed banning gay people from receiving legal representation. You (a lawyer) have investigated this law and found no reason for it to be unconstitutional, invalid, or otherwise unenforceable, because the laws in your country just suck that way. Can you justify representing a gay person in violation of this law as your ethical duty as a lawyer who believes that access to counsel for everyone is a fundamental ethic of lawyering, or would such an action be a textbook example of unethical legal practice?
Just to be clear, this question is from the perspective of the theory and philosophy of law and legal practice rather than a question about any specific jurisdiction. If this has been formally addressed in any specific legal system or jurisdiction, an answer from the perspective is welcome. For example, "The Supreme Court of Canada specifically ruled on this in 1973, here's what they said....".
Also to be clear, this question is about organized professional ethics (e.g. as ruled upon by bar committees and discussed in legal studies journals) rather than personal or religious moral codes.