The two are not equivalent. The BSA is a private organization. Whereas judges are holders of public office. The BSA can, in fact, set it's own membership qualifications, with little interference from the state. Whereas the membership qualifications for public office are a matter of public law, including the U.S. Constitution. If the qualifications set forth are in violation of the U.S. Constitution, then they are invalid and cannot be enforced.
It seems to me that a large number of judges probably belong to organizations that discriminate very heavily against homosexuals; namely, almost all mainline churches. Would this law, then, prevent a California judge from being Roman Catholic? Or Baptist? Or a member of the Armed Forces?