President Trump and Defense Secretary Jim Mattis at Naval Station Norfolk in Norfolk on July 22. (Jonathan Ernst/Reuters)

THE WHITE HOUSE timed its announcement of a ban on transgender recruits in the military amid a flurry of other events Friday. Hurricane Harvey was charging toward the Texas coast, and the president’s pardon of convicted former Maricopa County, Ariz., sheriff Joe Arpaio was stirring controversy. That the White House didn’t want to call much attention to its discriminatory treatment of transgender people is understandable, because the change in policy is without logic or need and has received bipartisan criticism. It has the potential to do great harm and must not be allowed to stand.

President Trump’s order directs the Pentagon not to permit transgender individuals to join the military, something he had promised in July with an announcement on Twitter that surprised not only Congress but also the military leadership. The long-term fate of transgender people currently in the armed services remains unclear; the directive gives Defense Secretary Jim Mattis the authority, in consultation with the secretary of homeland security, to determine if current personnel can continue to serve based on considerations of “military effectiveness,” “lethality” and “budgetary constraints.” On Tuesday, Mr. Mattis released a statement that while the matter is under review, the status of those personnel would remain unchanged.

Extensive review of the issue conducted by the Obama administration, including a study by the Rand Corp., found no adverse impacts to troop readiness and minor costs. Even more compelling evidence is found in the real-life experience and able service of thousands of America’s transgender veterans and active service members. More than a dozen other countries allow transgender troops to openly serve in the military without any problems.

Mr. Mattis has six months to develop a plan, so let’s hope more thought and study go into his handling of this issue than the spur-of-the-moment political whim that apparently gave rise to Mr. Trump’s tweet. Friday’s memo seems to suggest the possibility of Mr. Trump changing his mind (“The Secretary of Defense . . . may advise me at any time, in writing, that a change to this policy is warranted”).

But a better bet in ending this discriminatory policy may lie in the courts or with Congress. Lawsuits, including by the American Civil Liberties Union, have already been filed challenging the policy as violating the equal protection rights of transgender service members. Sen. Kirsten Gillibrand (D-N.Y.), along with Sen. Cory Booker (D-N.J.), plans to propose legislation that would block the ban once Congress is back in session. The Republican lawmakers who spoke out against the policy change after Mr. Trump’s July tweets, including Sens. John McCain (Ariz.) and Orrin G. Hatch (Utah), need to give meaning to their words and support that effort.