Another ill-conceived and mean-spirited policy reversal attempted by President Donald Trump has been blocked by a federal court. This one would have banned transgender individuals from serving in the military and would have ordered the discharge of existing transgender troops by next spring.

Appearing to act on impulsivity and an irresistible chance to undo another Barack Obama initiative, Trump last summer tweeted that the military should not be “burdened with the tremendous medical costs and disruption that transgender in the military would entail.” As is too often the case, he had no proof to back up his claims. He cared little that Obama ordered the change based on recommendations from his senior military and defense leaders. Those recommendations were further backed up by a detailed report from the RAND Corporation, which found that the presence of transgender troops would have “little or no impact on unit cohesion, operational effectiveness or readiness.

U.S. District Judge Colleen Kollar-Kotelly, in her ruling, noted that Trump’s ban likely would violate the equal protection clause of the Constitution. “All of the reasons proffered by the president for excluding transgender individuals from the military in this case were not merely unsupported, but were actually contradicted by the studies, conclusions and judgments of the military itself,” Kollar-Kotelly wrote.

Trump is not only the president, he is commander in chief of the nation’s military. They are not chess pieces, to be moved on a whim. They are humans who have pledged their loyalty and their lives to the service of this country and its leader. They deserve more from this president than his desire to wreck whatever displeases him.

Defense Secretary Jim Mattis, exhibiting more compassion than his leader, took it upon himself to issue a remarkable “interim guidance” that stated: “First and foremost, we will continue to treat every Service member with dignity and respect.”

That’s good, but it’s not enough. Congress should exercise its authority as an independent branch of government and pass bipartisan legislation being led by Sen. John McCain, R-Ariz., to take the matter out of Trump’s hands and allow transgender individuals the same opportunity afforded others — to serve their country with honor.