The couple and their lawyer did not return calls on Friday, but earlier in the week, they said they were devastated and caught off guard by the judge’s ruling. “It’s not fair and it’s not right,” Ms. Hoagland told a television station, KUTV. “And it just hurts me really badly, because I haven’t done anything wrong.”

Roberta A. Kaplan, a lawyer representing a group of couples who sued recently to overturn the Mississippi statute, said, “I think it’s clear after Obergefell that the government cannot discriminate against gay people, especially relating to anything in the sphere of family life.” But there are bound to be holdouts who will continue to fight, she said, as some local officials, notably Kim Davis in Kentucky, have done on marriage licenses.

Ellen Kahn, director of the children, youth and families program at the Human Rights Campaign, agreed, saying that the big obstacle that remained was not the law, but the attitudes of state and county employees who assess people’s fitness to be foster or adoptive parents and place children with them. “There are ways that you can avoid overtly discriminating, but your bias can come into play,” she said.

The legal dispute involving Judge Johansen is the first of its kind in Utah, because same-sex couples’ foster parenting is such a new phenomenon, said Ashley Sumner, a spokeswoman for the Division of Child and Family Services. “We want to keep children stable in their homes,” she said. “Our position is that it’s in the child’s best interest to stay with the foster family.”

On Friday, Judge Johansen amended his order, striking the sentence, “The court believes that it is not in the best interest of children to be raised by same-sex couples,” and a list of problems he said were more common among such children. He also removed the requirement to take the baby girl from her home by next week.

But he left room for doubt by keeping another sentence, only changing the words “its belief” to “a concern.”

“The court cited a concern that research has shown that children are more emotionally and mentally stable when raised by a mother and father in the same home,” he wrote. That view has been challenged by many studies and is not generally accepted by social scientists.

The order states that the girl was abused and that her father is imprisoned, so she is not a candidate for services aimed at reuniting children with their biological parents. Her birth mother, it says, “verbally stipulates to the termination of reunification services with her, and she indicates a desire to voluntarily relinquish her parental rights to the child.”