Sometimes yes, sometimes no.
There are four main canons of judicial ethics in the U.S. which have some sub-points, which explain how judges should do their jobs:
CANON 1
A judge shall uphold and promote the independence, integrity, and
impartiality of the judiciary, and shall avoid impropriety and the
appearance of impropriety.
Rule 1.1
Compliance with the Law
Rule 1.2
Promoting Confidence in the Judiciary
Rule 1.3
Avoiding Abuse of the Prestige of Judicial Office
CANON 2
A judge shall perform the duties of judicial office impartially,
competently, and diligently.
Rule 2.1
Giving Precedence to the Duties of Judicial Office
Rule 2.2
Impartiality and Fairness
Rule 2.3
Bias, Prejudice, and Harassment
Rule 2.4
External Influences on Judicial Conduct
Rule 2.5
Competence, Diligence, and Cooperation
Rule 2.6
Ensuring the Right to Be Heard
Rule 2.7
Responsibility to Decide
Rule 2.8
Decorum, Demeanor, and Communication with Jurors
Rule 2.9
Ex Parte Communications
Rule 2.10
Judicial Statements on Pending and Impending Cases
Rule 2.11
Disqualification
Rule 2.12
Supervisory Duties
Rule 2.13
Administrative Appointments
Rule 2.14
Disability and Impairment
Rule 2.15
Responding to Judicial and Lawyer Misconduct
Rule 2.16
Cooperation with Disciplinary Authorities
CANON 3
A judge shall conduct the judge’s personal and extrajudicial
activities to minimize the risk of conflict with the obligations of
judicial office.
CANON 4
A judge or candidate for judicial office shall not engage in political
or campaign activity that is inconsistent with the independence,
integrity, or impartiality of the judiciary.
The duties of impartiality and independence may require a judge to ignore public opinion. But there are also circumstances in which public opinion is relevant, usually, in circumstances where a judge has significant discretion. Rules 1.1, 2.2, 2.3, and 2.4 often require a judge to ignore public opinion. Rules 1.2, 2.8, 2.9. 2.10, 2.11, and almost all of the rules under Canon 3 and Canon 4, often requires a judge to consider public opinion.
Judges aren't umpires. As a judge at a recent seminar in Kansas explained:
[A]t least for conscientious judges, legal questions have an ethical
dimension. The complexities, paradoxes and uncertain boundaries of
legal decisions make it impractical for judges to plainly follow the
law wherever it leads, he said.
“It is a bit more complicated than that,” Stegall said. “Mature common
sense people of all stripes really know this intuitively. I do find it
interesting, however, how uncomfortable it often makes us to admit as
much.”
He said judges could be left in a quandary when laws or court rules
lacked objective, measurable standards and required members of the
judiciary to fill in the blanks.
“That’s when the subjective experiences of judges at least threaten to
be brought forward in the decision of the court[.]"
For example:
In sentencing a criminal defendant in cases where the judge has discretion in making that decision.
In determining an appropriate amount of non-economic damages or punitive damages or damages to reputation following a trial to the court.
In determining the likelihood that an alleged trademark infringement will cause confusion to the public.
Determining if material is obscene in light of "prevailing community standards"
Determining if a punishment is cruel and unusual.
In determining if injunctive relief harms the public interest.
In determining if a name change harms the public interest.
In evaluating the norms and customs of a community when this is an element of a legal claim, e.g. concerning what constitutes "good faith" in circumstances when it is defined broadly, and in determining what constitutes information that a person has a duty in good conscience to disclosed in a fraudulent concealment case.
In weighing how serious it would be for a criminal defendant to be freed prior to trial when weighing how strict conditions of pretrial release should be.
When evaluating which rule of law should be selected in cases of first impression that are not squarely controlled by other precedents.
When evaluating if a failure to recuse from a case would create an "appearance of impropriety."
When evaluating if a criminal defendant can receive a fair trial in a particular court venue given public opinion and pretrial publicity that may be pervasive in a potential jury pool.
So, the question cannot be answered in the abstract. One needs to know more about the context of the particular issue presented to know when it is and is not appropriate for a judge to consider public opinion in making a ruling.
The structure of the judiciary also provides some implicit guidance. Most states judges are either elected or subject to non-retention based upon a popular vote, which is a powerful constitutional message to judges that they should not be entirely divorced from the public sentiment that their decisions lead to. Even appointed judges are frequently political appointees suggesting that those systems too, although to a lesser degree, acknowledge that some recognition of public opinion is unavoidable and often appropriate.
But there is consensus that judges are not pure politicians and should consider public opinion only in circumstances when it advances their mission and duty, and not when it interferes with their independence and integrity.