A judge can rule however they please, but if it goes against legislated law or precedent, it can (and should) be appealed. Sure, if the highest appellate determines the law says something different than it really does, that’s that, but it’s not like most judges have carte blanche to determine the outcome of any legal entanglement on a whole.