By a law, so by a really big rule book. Laws need to be written and brought into effect by the legislature.
Courts only interpret laws, they can’t make one (except for the constitutional court that can make decisions with law-like quality that have direct binding effect)
Now, lawyers and courts often look at how other courts decided in similar cases and point to those decisions and the legal reasoning laid out by the court, but it is common that even even the higher levels of courts disagree on a subject.
Even higher court decisions have no binding effect in other cases to other courts, including lower courts. It’s not uncommon that lower courts diverge from decisions of their direct appeal courts - the Landgericht Hamburg is pretty notorious for having its decisions in press matters regularly overturned on appeal.
Versus the bias of one judge colouring how law should be decided? Judges are supposed to interpret the law, not create it. A strong legislative framework and collaborative atmosphere between the legal and political communities should remove the need for something like case law.
That already exists. Higher courts decisions then become considerations on appeal. Usually the decisions aren't just biased either but based on previous congressional rules and law, but there are a lot of times where congresses rules are ambiguous or lacking and has become so ineffective that justices have no choice but to make a ruling or leave people vulnerable.
So is there just a really big rule book? How is legality decided?