The U.S. Supreme Court announced a new rule on judicial bias in 2016. Although the rule might not apply to lots of cases, it highlights the fact that judges are supposed to be impartial.
A "recusal" occurs when a judge who would have heard a case doesn't preside over it. The judge is removed from the case, whether because of a motion by the prosecution or defense or because of the judge's independent decision. Recusals usually happen because of some kind of conflict of interest.
In Williams v. Pennsylvania, Williams had been convicted of murder and sentenced to death. His lawyers fought the conviction and sentence over the course of many years. Eventually, a Pennsylvania court stayed the defendant's execution and ordered a new sentencing hearing. (579 U. S. ____ (2016).)
The Pennsylvania Supreme Court vacated the order for a new sentencing hearing. The chief justice participated in the decision to vacate after rejecting a request that he recuse himself.
Why the recusal request? Because the chief justice had been the district attorney who gave official approval to seek the death penalty against Williams all those years ago.
Basing its decision on the 14th Amendment's Due Process Clause, the U.S. Supreme Court concluded that the chief justice had to be recused. It commented that a likelihood of bias by a judge that "is too high to be constitutionally tolerable" requires recusal. More specifically, it decided that a judge who has had "significant, personal involvement as a prosecutor in a critical decision regarding the defendant's case" must recuse him or herself.
If you want to know about your options as a criminal defendant, consult a lawyer with experience in your jurisdiction. Rules and practices vary. For example, lots of states have rules on judicial recusal that are stricter than the Williams holding.