The Washington State Supreme Court issued a unanimous ruling April 6 prohibiting judges from considering sexual orientation in custody proceedings. Its decision clarifies a troubling ambiguity in state law that had previously allowed judges to favor heterosexual parents over gay parents. The court emphatically closed this loophole, barring judges from using pretext to inject anti-gay animus into custody disputes.

In re Marriage of Black, the case in question, involved a divorced opposite-sex couple, Rachelle and Charles Black. The Blacks have three children, whom they raised as conservative Christians. In 2011, Rachelle came out as gay, moved into a basement room, and began dating a woman. She filed for divorce in 2013. A judge appointed a guardian ad litem, Kelly Theriot Leblanc, to observe the Blacks’ children and recommend custody determinations.

Leblanc told the judge that Rachelle’s “lifestyle choice”—i.e., her sexual orientation—could harm the children due to its “controversy.” She also asserted that Rachelle was “on a campaign to re-indoctrinate the children” and that her orientation would cause her children to be bullied. Leblanc concluded that Rachelle’s relationship with a woman would injure the children due to their strict religious upbringing. She recommended that Charles receive primary custody, and that Rachelle be forbidden from:

… [H]aving further conversations with the children regarding religion, homosexuality, or other alternative lifestyle concepts and further, that she be prohibited from exposing the children to literature or electronic media; taking them to movies or events; providing them with symbolic clothing or jewelry; or otherwise engaging in conduct that could reasonably be interpreted as being related to those topics.

Amazingly, the judge adopted these recommendations, writing that Rachelle’s “homosexuality” would be “very challenging” for the children to “reconcile [with] their religious upbringing.” He therefore granted Charles primary custody as well as sole decision-making authority regarding the children’s religion, education, and day care. He also barred Rachelle from discussing religion or sexuality with her children. An appeals court blocked the judge’s gag order and his reward of sole decision-making authority to Charles. But it upheld the judge’s decision to give Charles primary custody.

This bizarre decision is the result of contradiction in Washington state law. In 1983, the Washington State Supreme Court held that a parent may not lose custody or visitation rights simply because she or he is homosexual. But in 1996, the court created a workaround to this rule in a case involving a gay dad and a straight mom fighting over custody of their children. The family were devout Jehovah’s Witnesses; the mother argued that her gay ex-husband could no longer raise the children in the faith because of his orientation. A judge awarded her primary custody—not because the father was gay, he insisted, but because his homosexuality would disrupt the children’s religious upbringing. The state Supreme Court affirmed his decision, reasoning that the father was not disfavored “solely because of his sexual orientation” but rather because the children’s religion conflicted with his orientation.

This exception, of course, poses a glaring problem: It allows homophobic judges to favor straight parents over gay ones by using religion as a proxy for orientation. And that’s why the Washington State Supreme Court finally did away with it in In re Marriage of Black.

“Even if a parent’s sexual orientation is contrary to the children’s religious values,” the court wrote, “a trial court may not consider it in a custody determination unless the evidence shows direct harm to the children. … Courts must remain neutral toward a parent’s sexual orientation.” That requirement still applies in cases where “children are allegedly uncomfortable with homosexuality due to their religious upbringing.” Judges may not cite this discomfort in rendering custody decisions; “such reasoning,” after all, “unfairly punishes a parent in a custody proceeding on the basis of her sexual orientation.”

The court might have added that this reasoning is also unconstitutional. Although it cited Obergefell v. Hodges, the court rooted its decision in state statutes and precedents, mostly leaving the federal Constitution out of it. That makes sense for a state Supreme Court. But it is worth noting that Obergefell, its predecessors, and the 1984 decision Palmore v. Sidoti clearly proscribe anti-gay animus in custody proceedings. In Palmore, the U.S. Supreme Court found that courts may not deny custody to a divorced parent because she entered an interracial relationship. The same logic should apply when a divorced parent enters a same-sex relationship. As I explained in a recent UCLA Women’s Law Journal article, such animus infringes upon the constitutionally protected “equal dignity” of sexual minorities.

Regardless, last week’s decision is a triumph for LGBTQ advocates and, in particular, Legal Voice, the feminist group that representated Rachelle Black. It is also an excellent model for other state courts. We are not far away from the era when judges freely labeled homosexuality an “abominable sin” and permitted custody decisions based exclusively on homophobia. Courts should follow Washington state’s lead in stamping out this animus even when it is dressed in pretext. It’s good for parents, good for children—and as a bonus, mandated by the United States Constitution.