scotland
While the circumstances of the judge's misconduct would be very unusual, there is a well-established path for dealing with situations when a judge is biased for some reason.
As background, murder trials take place exclusively in the High Court of Justiciary, where our putative bad judge would be Lord Miller, one of many available judges hopefully not all murderous.
A judge is not meant to preside over a case where he or she has a real or apparent conflict of interest. Recusal ("declinature of jurisdiction") can take place either on the judge's own initiative, or as the result of a motion from one of the parties to the case. If the judge refuses that motion then this can be appealed to the Court by means of a "bill of advocation". That is also the mechanism for objecting to instances of bias or prejudice which emerge during the trial. The bill of advocation will be considered by a panel of at least three judges, together with any opposing submissions by the other party.
If there are other unusual problems with the handling of the case - which we could imagine if the guilty judge is craftily manipulating proceedings - then Alex's counsel could raise a "petition to the nobile officium". This is an appeal to the extraordinary supervisory jurisdiction of the Court, by which it can deal with any oddity or injustice for which there is not an existing mechanism. This ends up before a multi-judge bench in the same way.
Among the possible remedies are that the case be "deserted simpliciter", which means that it stops right now because it would inevitably be unfair if it continued (HMA v Fleming 2005 JC 291 at 35). In the circumstances as described, this bars future prosecutions of Alex for the same offence.
In the event that Alex did not have proof in hand that Lord Miller actually did the murder instead of him, but only something like "Miller was personally acquainted with Alicia", the High Court might instead order that Alex's trial be "deserted pro loco et tempore". This lets the prosecutor issue another indictment and try again with a different judge. Ordinarily, desertion pro loco is only available at an early stage of the trial.
The prosecution is also able to halt an ongoing trial at any stage before sentencing. (A judge cannot pronounce a sentence unless the prosecutor has made a motion for him to do so; and see e.g. Noon v HMA 1960 JC 52, "it has always been part of our procedure that, even after the guilt of an accused has been established, the prosecutor should have the opportunity, if he thinks fit, to withdraw the case and allow the accused to go free".) If Alex has evidence that he did not do the murder, and/or that Miller did, then sharing this with the prosecutors would hopefully be effective in halting the trial, even in the face of a reluctant judge.
If all of this emerges after conviction, then Alex could appeal, either directly or via the Scottish Criminal Cases Review Commission. An appeal is the normal way. The SCCRC is an additional line of defence for when the avenues of appeal have been exhausted.
As to Lord Miller himself, he would be prosecuted just like anybody else. He would also be removed from judicial office, though the process is a bit involved. The First Minister has to convene a special tribunal, and lay their report before the Scottish Parliament. They can then authorize the First Minister to recommend the judge's removal to the King.