President Trump’s decision to wind down the policy known as Deferred Action for Childhood Arrivals—which shields from deportation nearly a million “Dreamers,” aliens brought to the U.S. as children—has drawn a predictable response. The president already faces lawsuits from 19 states, as well as complaints from the University of California and immigrants nationwide.

Leading the charge is Eric Schneiderman, New York’s state attorney general, who argues Mr. Trump lacks the authority to revoke DACA because he is racist. Seriously. In the complaint, filed last week, the attorneys general proffer other arguments based on the particulars of administrative law, but at bottom they assert that any action Mr. Trump takes that harms the Dreamers is tainted by his statements about Mexicans. That claim is not only legally unsound but a threat to the constitutional separation of powers.

The states first assert that the Trump administration cannot rescind DACA without seeking feedback from the public. If that argument is correct, it would seem to nullify DACA, since the Obama administration itself bypassed the rule-making process known as notice and comment when it issued the policy in 2012. ( Janet Napolitano, who issued the DACA memo as secretary of homeland security, is now suing Mr. Trump in her capacity as president of the University of California.)

In announcing DACA’s rescindment last week, U.S. Attorney General Jeff Sessions argued that the policy is unlawful—an “open-ended circumvention of immigration laws” and “an unconstitutional exercise of authority.” If Mr. Sessions is correct, the government is required to stop breaking the law. If courts rule DACA to be lawful, then a judge could find, as the states assert, that Mr. Sessions’s justification was bogus, and thus inadequate to justify withdrawing the policy.

But proving Mr. Sessions’s case shouldn’t be hard. In 2014 the Obama administration issued a similar policy called Deferred Action for Parental Accountability. It was intended to protect aliens with children who are U.S. citizens, but a 2015 federal court order (still binding on the executive branch) blocked its implementation. Texas and 25 other states asserted that DAPA was illegal. A district judge in Brownsville, Texas, agreed, as did the Fifth U.S. Circuit Court of Appeals, whose ruling was left to stand when the Supreme Court split 4–4. Because the 2014 policy had not yet gone into effect, the judicial analysis was based almost entirely on how DACA had been implemented. There are some differences, but by the Obama administration’s own admission, the 2014 policy was meant to be “similar” to its precursor.

The district judge in Brownsville wrote he had heard evidence “that DACA applications are simply rubberstamped.” The government was unable to identify a single applicant who met the DACA criteria but was denied for discretionary reasons. Given that the policy was justified as an exercise of prosecutorial discretion, Mr. Sessions’s conclusion that it is unlawful stands on terra firma.

Critically, the Trump administration does not need to be correct about DACA’s illegality beyond a reasonable doubt. So long as DACA’s wind-down is not “arbitrary and capricious,” the courts may not block it. Even if a judge did find the decision capricious, he cannot order the executive branch to approve new DACA applicants. Courts lack the power to compel the executive branch to take discretionary acts. At most, a judge could order the government to seek public comment or reconsider its decision.

Thus the current litigation, even if successful, may not help a single immigrant. Since Mr. Trump is not revoking extant DACA approvals, which last two years, the policy may simply phase out by the time the lawsuits run their course.

That brings us to Mr. Schneiderman’s most unsettling claim: that Mr. Trump can’t revoke DACA because he is racist. “The President has demonstrated a willingness to disparage Mexicans in a misguided attempt to secure support from his constituency,” the states’ complaint argues, “even when such impulses are impermissible motives for directing governmental policy.”

The filing cites a litany of Mr. Trump’s offensive comments—his warning about Mexican “rapists”; his disparagement of Univision anchor Jorge Ramos ; his reference in a presidential debate to “bad hombres”; his attacks on Judge Gonzalo Curiel —as well as his pardon of Joe Arpaio, the former sheriff of Maricopa County, Ariz.

The states argue these remarks establish as a matter of law that Mr. Trump has a racist heart and his administration’s actions are therefore irrational. Although Mr. Trump’s comments should have given pause to his voters, courts cannot properly consider them in evaluating this policy.

The president’s opponents are free to scroll endlessly through @RealDonaldTrump, and what they find there may carry political weight. But courts need a limiting principle. Namely, the judiciary should consider statements from Mr. Trump only if they are directly relevant to the case at hand.

Federal judges have already grossly erred by citing Mr. Trump’s campaign statements to justify halting his executive orders on immigration. In those cases, at least there was some connection between the final policy and what Mr. Trump had proposed during the campaign. By contrast, the comments Mr. Schneiderman cites have nothing to do with DACA.

The judiciary should rebuff this attempt to deprive the president of his lawful authority. It’s up to Congress to make the humane choice and enact legislation providing the Dreamers with legal status.