Courts are generally required to follow the law. However, to the extent equitable relief is sought (an injunction, a restraining order, specific performance of a contract), courts can and do look at moral and ethical considerations. One of the favorite sayings in the law is: "He who seeks equity must do equity."
Disclaimer: The response given is not intended to create, nor does it create an ongoing duty to respond to questions. The response does not form an attorney-client relationship, nor is it intended to be anything other than the educated opinion of the author. It should not be relied upon as legal advice. The response given is based upon the limited facts provided by the person asking the question. To the extent additional or different facts exist, the response might possibly change.
I think most lawyers would say that there's a certain amount of ethical and moral consideration in formulating the legal principles that are used in contract interpretation. Ideally, that shouldn't be incompatible with enforcing what the parties have agreed to.
Disclaimer: Please note that this answer does not constitute legal advice, and should not be relied on, since each state has different laws, each situation is fact specific, and it is impossible to evaluate a legal problem without a comprehensive consultation and review of all the facts and documents at issue. This answer does not create an attorney-client relationship.
I agree with my colleagues and think it also depends on the circumstances. Judges are people, too, and they have their own sense of "right and wrong", as well as a duty to uphold the law. Sometimes it's a balancing act.
If both sides have some moral and ethical "issues" then this seems to cancel each other out. If one side is the bad apple then many judges really stretch things to punish "the creep" and this sometimes results in a very bad decision by the court (from a strictly legalistic point of view) and often thse sorts of cases get appealed and end up making new law or clarifying the rules or at least setting up an example of how to analyze very unacceptable behavior.