A federal judge upheld the core of California’s sanctuary laws Thursday, restricting state and local cooperation with federal immigration agents, and sent a terse message to the Trump administration: Solutions to the immigration impasse must come from Congress, not the courts.

U.S. District Judge John Mendez of Sacramento halted enforcement of one new state law that penalizes private employers who allow immigration agents into their workplaces. But he said the state was not interfering with U.S. immigration policy in its main sanctuary law, which prohibits police and sheriff’s offices and state authorities from notifying federal agents of the upcoming release dates of undocumented immigrants in local custody.

“California’s decision not to assist federal immigration enforcement in its endeavors is not an ‘obstacle’ to that enforcement effort,” said the judge, an appointee of President George W. Bush. “Standing aside does not equate to standing in the way.”

The restriction is a central feature of SB54 by state Sen. Kevin de León, which the Legislature passed last year and Gov. Jerry Brown signed.

Attorney General Jeff Sessions sued California in March, arguing that SB54 and two other laws signed by Brown were unconstitutional intrusions on federal turf and were aimed at interfering with the Trump administration’s immigration enforcement policies. He steered the case to Sacramento, a more conservative judicial district than San Francisco, where suits by local governments defending their sanctuary policies were already pending before judges appointed by Democrats.

Now Playing:

Although Mendez issued an injunction against the main provisions of the law on workplace entry, he concluded his 60-page ruling by essentially telling Sessions he had picked the wrong battleground by going to court.

“If there is going to be a long-term solution to the problems our country faces with respect to immigration policy, it can only come from our legislative and executive branches,” Mendez said. “It cannot and will not come from piecemeal decisions issued by the judicial branch.”

Brown agreed. “Only Congress can chart the path forward by rising above mindless, partisan divisions and working together to solve this problem,” the governor said in a statement after the ruling.

The opposing sides in the lawsuit were unyielding.

Justice Department spokesman Devin O’Malley said Mendez’s injunction against the workplace law was “a major victory for private employers in California who are no longer prevented from cooperating with legitimate enforcement of our nation’s immigration laws.”

He said the department was “disappointed that California’s other laws designed to protect criminal aliens were not yet halted,” but did not say whether Sessions would appeal.

De León said an appeal would reflect Sessions’ fixation on the issue. “The attorney general is obsessed with immigrants and people who don’t look like him or talk like him,” the state senator told reporters.

State Attorney General Xavier Becerra, whose office defended the law, said Mendez had issued “a strong ruling against federal government overreach.”

Assemblyman David Chiu, D-San Francisco, author of the law that Mendez largely blocked, said the ruling overall was “a rebuke to the racist immigration policies of President Trump and U.S. Attorney General Jeff Sessions.”

Chiu also said the ruling, while preventing the state from punishing employers who cooperate with federal agents, does not prevent “employers who care about their immigrant employees” from denying access to agents unless they have judicial warrants

In suing the state to block the new immigration laws, Sessions argued that de León’s SB54 violated a U.S. law that requires states to let police inform federal agents of the immigration status of anyone in local custody. Sessions contended that someone’s immigration status includes release dates, and that local officers should hold undocumented immigrants in custody for delivery to federal officers.

Mendez said California allows police and sheriff’s offices to communicate detainees’ immigration status to federal agents but is not obliged to inform them of release dates or the detainees’ home addresses, which are also confidential under SB54. The state law’s restrictions do not apply to immigrants charged with serious crimes. They also give sheriff’s offices the choice of making all inmates’ release dates public information, an option that sheriffs in a number of counties have exercised.

The federal government may not “commandeer” a state to enforce its laws, Mendez said. He also noted that prosecutors and law enforcement officials who support the California law have warned that state-federal cooperation in immigration enforcement could cause migrants to “fear approaching police when they are victims of, and witnesses to, crimes,” or when they seek public services.

Mendez also upheld a separate state law, AB103, authorizing California’s attorney general to inspect detention facilities that hold immigrants under contract with the federal government. Sessions contended the state has no business inside federally commissioned lockups, but Mendez said no U.S. law prohibits states from examining conditions of detention centers within their borders.

Chiu’s law, which the judge largely blocked, would impose fines on employers who voluntarily allow immigration agents to enter the workplace and search for unauthorized immigrants or examine employment records.

Previous state law had allowed employers to decide whether to permit immigration raids in private areas of the workplace. The new law, AB450, allows federal agents to enter only if they have a warrant from a judge, and otherwise fines employers between $2,000 and $5,000 for consenting to an initial entry and up to $10,000 for repeat entries.

The law “impermissibly discriminates against those who choose to deal with the federal government,” Mendez said.

He did uphold a provision of the law requiring employers to notify workers of upcoming federal inspections of their records, but said employers must be allowed to decide whether to admit federal agents.

Chronicle staff writers Melody Gutierrez and Hamed Aleaziz contributed to this report.

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com. Twitter: @BobEgelko