One of California's centerpiece laws designed to protect undocumented immigrants was dealt a setback this week, one which may ultimately boost the Trump administration's strict immigration enforcement efforts.

Late Thursday, an Orange County Superior Court judge ruled in favor of Huntington Beach, a city that has challenged state Senate Bill 54 (SB 54), declaring that it violated the city's right to local control. Also known as the California Values Act, the so-called sanctuary law bars local authorities from asking about the immigration status of people during routine interactions, or participating in most federal immigration enforcement actions.

Back in April, Huntington Beach — one of at least 121 charter cities in California — filed a complaint contending that the Golden State's Constitution gave it local autonomy and independence over certain laws, including police departments and local resources.

The ruling could boost federal immigration enforcement efforts, by giving the U.S. Immigration and Customs Enforcement agency more access to certain local jails. Prior to SB 54, federal immigration agents routinely received space within local prisons and jails when they requested, as part of enforcement efforts to identify and transfer immigrants with certain felonies to federal custody.

The California Attorney General's Office, which had fought the case, didn't respond to CNBC's request for comment.

The list of charter cities in California includes some of the state's largest, including Los Angeles, San Diego, San Francisco, San Jose and Fresno. There also are many medium-sized cities on the list, including some that have already passed measures against the state's sanctuary law policies.

However, Thursday's ruling didn't appear to apply to those other counties.

"To me, having SB 54 declared unconstitutional at any level is a massive victory [for the city] and a massive defeat for the state," said Michael Gates, the city attorney for Huntington Beach. He said the ruling doesn't just exempt the coastal city from the law, tut other charter cities throughout the state.

In March, the Trump administration filed a lawsuit in federal court against California, contending that three different state laws passed in 2017 to protect undocumented immigrants against deportation violate the U.S. Constitution. Those laws include SB 54, which was authored by state Senate leader Kevin de Leon, D-Los Angeles, who is a candidate running to unseat U.S. Democratic Senator Dianne Feinstein. De Leon's office didn't immediately respond to a request for comment.

In July, a federal judge in Sacramento upheld SB 54, a ruling that was appealed to the Ninth Circuit Court of Appeals.

Some opponents of SB 54 have said it jeopardizes the safety of the public, because it made it tougher to get incarcerated immigrants once they are released from jails into the custody of federal immigration agents. They say it can result in violent criminals being released back into communities.

In May, President Donald Trump invited a group of local officials opposed to California's sanctuary law policies to the White House to discuss the issue. At the meeting, Trump praised the officials for having "bravely resisted California's deadly and unconstitutional sanctuary state laws." The president also said the sanctuary policies are wrong because they provide a "safe harbor to some of the most vicious and violent offenders on earth."

Fred Whitaker, chairman of the Orange County Republican Party and an attorney, called Thursday's ruling "a good victory for the 121 charter cities and I think it also helps the case of the many general law cities that also have taken a stand in opposition to SB 54."

Whitaker believed the ruling could be a boost for GOP candidates running in Orange County, which has been ground zero for opposition to the sanctuary policies.

Earlier this year, the Orange County city of Los Alamitos was one of the first local jurisdictions to take a stand against the state's sanctuary law policies, and was followed by Huntington Beach, Dana Point, Laguna Niguel and Lake Forest.

The board of supervisors for several counties have also come out against the California sanctuary laws, including Orange, San Diego, Kern, Tehama, Siskiyou and Shasta.

"Most cities who are going to be arresting people are going to be booking those people into county jails, said Annie Lai, co-director of the Immigrant Rights Clinic at the University of California-Irvine. "So counties are a big part of this story and the counties would not be able to 'opt out' of SB 54."

WATCH: Here are the businesses profiting from immigration enforcement