Sometimes common sense prevails over craven politicians.

A judge in Virginia on Friday handed down a temporary ruling that seven school districts could keep their mask mandates in place — a setback to Gov. Glenn Youngkin, who had signed an executive order making masks optional in public schools.

Last month, Fairfax County, Prince William County, Alexandria, Arlington, Falls Church, Hampton, and Richmond Public Schools filed a lawsuit against Mr. Youngkin, who had issued the order on Jan. 15, the day he took office. The order went into effect on Jan. 24. Together, the seven districts serve more than 350,000 students.

On Friday, Judge Louise DiMatteo of the Circuit Court in Arlington County granted a temporary restraining order to the school districts while the case makes its way through court. The judge said that Mr. Youngkin did not have the power to override local school board policies on mask mandates. The districts involved in the suit issued a statement on Friday saying they were “pleased” with the ruling.

“The order allows schools to continue to protect the health and well-being of all students and staff,” the statement said. “While the legal process on this matter continues, today’s ruling preserves the existing policies and practices in Virginia school divisions, which include masking requirements.”

Macaulay Porter, a spokesman for Mr. Youngkin, said the governor was “going to appeal.”

“The governor will never stop fighting for parents’ ability to choose what is best for their children,” Mr. Porter wrote in an email. “The governor often said that this is not a pro-mask or anti-mask debate. It’s about parents knowing what’s best for their child’s health.”

Governor Youngkin’s own children attend private schools that mandate masks.