If migrants are already safe in another country, why shouldn’t they apply for asylum there before coming to the United States and applying here?

That’s the perfectly sound logic behind a rule Team Trump put in place Monday: Migrants who pass through another country will be ineligible for US asylum unless they’ve first sought it, unsuccessfully, in that third country.

Naturally, advocate groups promptly filed legal challenges to the rule, arguing that Congress hasn’t specifically OK’d it. Their lead lawyer, Lee Gelernt, claims that current law requires foreigners to seek asylum in a third country only if that country has a formal deal with Washington and can “ensure a safe and meaningful opportunity to obtain asylum” there.

That’s far from clear. Attorney General William Barr insists the rule “is a lawful exercise of authority provided by Congress to restrict eligibility for asylum.”

And if Barr’s wrong, then the law is nuts: The point of asylum, after all, is to offer refuge to foreigners who can prove they’d face serious danger (persecution, torture, death) if sent home. Those safely in a third country only face such threats if that country denies them asylum and tries to kick them out.

Virtually all of the 100,000-plus-a-month people now illegally crossing the southern US border have already passed through Mexico, and most through Guatemala, too. But neither now has a deal with DC that meets the standard required by the advocates’ lawsuit. Team Trump is trying for such agreements, but both nations seem inclined to let the migrants swamp US courts rather than their own.

Those US immigration courts now face a backlog of 900,000 cases and growing. As Barr put it, “The United States is a generous country but is being completely overwhelmed.”

Fact is, US asylum laws, as President Trump often notes, are wildly abused: A huge share of these migrants are coming here for economic reasons — they can earn far more with even a low-end job in America than they can back home — than out of any particular fear.

Even with lax asylum rules, courts wind up denying 80 percent of the requests — eventually. Yet the backlog ensures that this can take years.

By then, many applicants have families, jobs and obligations here. Often, they don’t even bother to show for their cases. Most wind up staying.

All of which makes US borders virtually meaningless — and a mockery of the law. Trump should have every right to impose sensible rules to stem this insanity.