Why do you assume that judges decide cases based on their political or ideological preferences? Don’t judges make decisions based on the applicable law in each case?
In the majority of cases, judges are bound by the law that applies in the case, and their job is simply to apply the law fairly to the facts. However, there are many cases in which the law is ambiguous, or no precedent clearly applies to the specific fact pattern. In these cases judges must exercise some discretion in deciding the case—how to interpret the ambiguous language of a statute, for example, or whether to choose one precedent or another. Over the course of many cases, the judge’s decisions sometimes form a clear pattern, which can be recorded and measured.
Numerous political science articles and legal studies have shown that judges have measurable political leanings, though these leanings frequently defy simplistic party affiliations like “Democratic” or “Republican.” See Party Affiliation as a Predictor of Judicial Voting Patterns for more details.