The state Supreme Court has voted to prohibit judges in California from belonging to the Boy Scouts because the 2.7 million-member youth organization bars gays and lesbians from becoming troop leaders.

The court announced Friday that its seven justices had voted unanimously to accept a February 2014 recommendation from its ethics advisory committee to ban Boy Scout membership. As of Jan. 21, 2016, judges affiliated with the Scouts will be in violation of the state Code of Judicial Ethics, which the court oversees, and could face removal from office.

California has been among 23 states with an ethical code that prohibits judges from belonging to organizations that discriminate on the basis of sexual orientation. But the state’s Supreme Court in 1996 approved an exemption, unique to California, for “nonprofit youth organizations” to accommodate judges affiliated with the Boy Scouts.

The Bar Association of San Francisco and other legal organizations sought to repeal that exemption in 2003. The court refused, and instead instructed judges to disclose connections to the Boy Scouts when they heard cases involving gay rights and related issues, and to disqualify themselves for any conflicts of interest.

At the time, the Scouts also barred gay youths as members, a policy the U.S. Supreme Court had upheld in 2000. The organization repealed that ban at a national meeting in May 2013, effective the following January, but maintained the prohibition on gay and lesbian youth leaders.

“The people of California have a right to an impartial and unbiased judiciary,” Richard Fybel, a state appeals court justice in Santa Ana and chairman of the high court’s ethics advisory committee, said Friday. “This is important to accomplishing that.”

The Boy Scouts could not be reached for comment Friday evening.

Judges group supportive

In a statement that responded to the committee’s proposal last year, Deron Smith, a spokesman at Boy Scouts headquarters in Irving, Texas, said the Scouts “would be disappointed with anything that limits our volunteers’ ability to serve more youth. ... Today, more than ever, youth need the character and leadership programs of Scouting.”

The proposal had drawn a mixed response from judges. In written comments to the court, one opponent said the prohibition would elevate “gay rights above religious freedom rights,” and another said it would interfere with judges’ rights to raise their children as they choose.

But the California Judges Association, which represents 1,575 of the state’s 2,000 judges, supported the ban.

The new rules would still allow judges to belong to religious organizations whose beliefs or practices were discriminatory. Many Boy Scout troops are affiliated with churches, and Fybel, the committee chairman, said some judges have argued that their troop was a religious organization that should remain exempted.

Not a religious group

But he cited the Boy Scouts’ website, which describes the Scouts as “one of the nation’s largest and most prominent values-based youth development organizations” and does not refer to any religious affiliation.

The Boy Scouts also ban atheists and agnostics as members. California’s judicial ethics code forbids membership in organizations that discriminate based on religion, among other categories, but has not applied it to the Scouts in the past because of the exemption for nonprofit youth groups.

The Supreme Court took the vote at its private conference on Wednesday, but did not announce it until Friday. The court waited to take up the issue until it had a full complement of seven members, including Gov. Jerry Brown’s new appointees, Justices Mariano-Florentino Cuellar and Leondra Kruger, who took office Jan. 5.

Bob Egelko is a San Francisco Chronicle staff writer. E-mail: begelko@sfchronicle.com Twitter: @egelko