WHEN PRESIDENT TRUMP announced last fall that he would require states and localities to consent to the resettlement of legal, thoroughly vetted refugees in their communities, he bragged at a campaign rally in Minnesota, “Believe me, no other president would be doing that.” Mr. Trump was right. In four decades, no other president has done so — and there are excellent reasons for that.

First among them is that his executive order — in effect an invitation for Americans to turn away prospective neighbors who might look, sound or think different — reinforces and encourages the most exclusionary, divisive, intolerant faults in America’s social fabric. By doing so, it diminishes the country, not least in the eyes of a world that has long looked to the United States as a leader of humanitarian causes such as resettling the planet’s most desperate people.

No one believes Mr. Trump is swayed by such arguments. But here’s another: What he did is probably illegal.

This past Wednesday, Judge Peter J. Messitte, of the U.S. District Court in Maryland, granted a temporary injunction freezing Mr. Trump’s order, and in the process offered a lucid explanation of why it is unlikely to pass legal or constitutional muster. He cited a raft of precedents, including by the Supreme Court, reserving for the federal government — not states, let alone localities — the exclusive power to admit or deny immigrants. He also demonstrated that the president’s stance flies in the face of Congress’s intent when it established the current refugee system, in 1980, and subsequently.

That law provides what it calls “comprehensive and uniform provisions” to resettle and provide for refugees admitted after rigorous screening by U.S. agencies, a process that takes about two years. It establishes a system of consultation between federal and local officials designed to ensure a smoothly functioning system. Nowhere does it grant states and localities a veto; in fact, in amending the law to provide for more consultation, in 1986, the House Judiciary Committee noted in a report that it did not intend to grant states and localities any veto.

Mindful of the legislation, Justice Department lawyers, tasked with defending the president’s order, tried to pretend it did not amount to a veto for states and localities; rather, they said, it was meant only to “enhance the consultation.” The judge rightly labeled that “Orwellian Newspeak.”

Mr. Trump’s move was an appeal to the nation’s worst instincts. Most Americans didn’t bite. Ahead of a deadline on Tuesday, at least 42 governors and scores of localities, including many with large Republican majorities, have announced they would accept refugees. Only Texas Gov. Greg Abbott (R) so far has declined; the judge’s decision denies him that power.

That won’t stop Mr. Trump from eviscerating the refu­gee program; he’s already slashed the annual limit on resettlements to 18,000, down from the 110,000 President Barack Obama announced in his last year in office. The open arms of most states and localities do send a convincing message, though — that Americans are not as fearful, hostile and small-minded as Mr. Trump evidently believes.

Read more: