Its why we have juries to be honest-
Judges are supposed to know the law well and give appropriate punishments. The fact that they don't give appropriate punishments based in case law is a travesty to be honest. Don't have a solution for this, other than shaming them basically and disbarring judges with super obvious biases.
For example: Wrongthink gets 10 years but rapist walks free because theyre transgender should be an automatic disbarment.
In the US, you do see states that have imposed mandatory minimums in a lot of areas to avoid this sort of excessive bias in judges, but vice versa, mandatory minimums for non-violent crimes, or marijuana related crimes, are just 'too controversial' for most so many courts have gotten rid of them entirely. Either way, theres a lot you can do to tweak the system, but this all rests on the concept that youre not living in clown world.