Attorney General Jeff Sessions unleashed a blistering assault on federal judges Monday, saying anti-Trump bias has led some to abandon their role as legal referees and become “political actors” erecting roadblocks to the president’s policies.

In unusually stark language, Mr. Sessions suggested judges could soon face “calls for their replacement” if they don’t cool it.

He blasted one judge who called the president’s policy toward illegal immigrants “heartless,” and said another judge put “the inner workings of a Cabinet secretary’s mind” on trial to pave a path to block the government from asking about citizenship on the 2020 census.

“Once we go down this road in American government, there is no turning back,” Mr. Sessions said in a speech to the conservative Heritage Foundation. “We are seeing it in case after case. When a hot-button policy issue ends up in litigation, judges are starting to believe their role is to examine the entire process that led to the policy decision — to redo the entire political debate in their courtrooms.

Just ahead of the speech Mr. Sessions told The Washington Times that he saw anti-Trump resistance at play in some of the judges’ moves.

“I have to say I think some of it is,” he said. “I regret saying that, but I’m afraid it’s true in some of these cases and if so, it’s very wrong.”

He added that unfair intervention from judges has left the administration in legal tangles, forcing the president to fight senseless and distracting cases.

“He has monumental responsibilities and no court without serious cause should interrupt the function of government. It takes untold hours and time to deal with these things. It slows up multiple agencies of government,” the attorney general told The Times.

Judges have been divided in their approach to Mr. Trump.

Some have delved into his Twitter account or looked back at statements he made during the campaign, citing them as evidence that justifies halting policy decisions made by Cabinet secretaries elsewhere in government.

Others, including a majority of justices on the Supreme Court in this year’s ruling upholding the president’s travel limits, looked chiefly at the policies themselves, saying that’s the crux of their judiciary’s role in the government overall.

In that case the majority in the 5-4 ruling said Mr. Trump was on firm national security grounds. The dissenters disagreed, with Justice Sonia Sotomayor saying the president overstepped security powers and illegally targeted Muslims.

Mr. Sessions didn’t mention that case, but most of the ones he did single out Monday stemmed from immigration-related fights.

He chided one judge who earlier this month issued an injunction blocking Homeland Security from phasing out special Temporary Protected Status for hundreds of thousands of migrants from El Salvador, Haiti and elsewhere.

Federal law says the Homeland Security secretary’s TPS decisions cannot be reviewed by courts, but the judge ruled he was reviewing the process by which the secretary reached the decision, not the decision itself.

One crux of his decision was Mr. Trump’s reported use of an insult to describe El Salvador and some African countries during a closed-door immigration meeting earlier this year, which U.S. District Judge Edward M. Chen, an Obama appointee, said showed “animus” that could have poisoned the administration’s entire decision-making process.

In his speech Monday, Mr. Sessions also criticized U.S. District Judge Nicholas Garaufis, who last year during a hearing told a Justice Department he couldn’t defend a policy “that is so heartless.”

Mr. Sessions criticized the judge at the time, telling him to stick to rulings on the law, not to opine about his political beliefs. The judge fired back, saying Mr. Sessions seemed “to think the courts cannot have an opinion.”

The attorney general replied Monday evening that “of course a judge can have political and policy opinions. But they should decide legal questions based on the law and the facts — not their policy preferences.”

Mr. Sessions said that when Congress fails to act, that is a decision. And courts cannot step in to do what Congress has decided not to do.

He called that “judicial encroachment,” and said it has become so bad that judges are trying to rehash the full decision-making of administrative actors in their courtrooms.

As part of that, judges are increasingly allowing intrusive legal “discovery” — the process of delving into records and decision-making to let judges review not just the final decision, but the way it was made.

Mr. Sessions said demanding handwritten notes from Cabinet secretaries or, in a case now before the Supreme Court, ordering the Commerce secretary to be deposed in the Census citizenship question case, goes too far.

“The Census question — which has appeared in one form or another on the Census for over a hundred years — is either legal or illegal,” the attorney general said. “The words on the page don’t have a motive; they are either permitted or they are not. But the judge has decided to hold a trial over the inner workings of a Cabinet secretary’s mind.”

He said it would be the equivalent of forcing judges to reveal their conversations with their law clerks when they were deciding what to write in their opinions, or forcing members of Congress to divulge their discussions with their staffers.

“Subjecting the executive branch to this kind of discovery is unacceptable. We intend to fight this and we intend to win,” Mr. Sessions said.