SAN DIEGO (AP) — The 14 defendants had been charged with entering the country illegally. But there was a problem: When their cases were called in court, they could not show up because they had already been deported.

U.S. Magistrate Judge William Gallo quickly concluded that none of the migrants could be prosecuted — a decision that struck at the heart of the Trump administration's zero-tolerance immigration policy, which calls for treating illegal border crossing as a common crime. He dismissed all the charges and ordered that all bond money be returned.

The same scene played out every day for several weeks in San Diego — another example of judges challenging President Donald Trump's moves on immigration in ways large and small. Last month, a different judge halted an administration policy to deny asylum to people who enter the country illegally.

The dismissals did not free any migrants or allow any of them back into the U.S. But the rulings defeated the purpose of zero tolerance, which is to notch convictions.

Gallo and other California judges forced the government to choose between deporting migrants immediately or risking that the criminal cases against them will be dropped. To avoid getting cases dismissed, the administration could not conduct the type of lightning-quick prosecutions that it practices elsewhere along the border.

Federal prosecutors introduced the mass hearings on immigration charges in California in July, adopting a model that has been in place for years in Arizona, New Mexico and Texas. The hearings soon began running past 6 p.m. regularly.

Defense attorneys frequently objected that they didn't have enough time to consult with their clients, who appeared in the same clothes they wore crossing the border a day or so earlier.

Then, on Sept. 17, Gallo announced that judges would no longer accept guilty pleas at initial appearances, as they do in Arizona and Texas. Instead, they began setting second hearings for five days later. Immigrants who posted bail before their return dates were deported.

"The government, in many respects, was duplicitous," Gallo said on a recent Friday, referring to the decision to deport defendants before they could return to court for resolution of their cases.

On the same day, Gallo dismissed charges against the 14 defendants, many of them Mexican men who were caught hiding amid boulders and thick brush in rugged mountains east of San Diego.

If convicted, first-time offenders can be punished by up to six months in prison. They can be charged with a felony if caught again.

The administration countered on Oct. 9, saying it would not deport people until their criminal cases were completed. That stopped cases from being dismissed but introduced new problems: Keeping people in custody for longer periods strained detention space and imposed higher costs.

"They wanted it to be a one-day thing, like it is across the whole border, because it's cheaper," said Jami Ferrara, who represents defense attorneys on a panel with judges and prosecutors working on the changes. "It's not a cheap system."

It is unclear how many cases were dismissed in San Diego, but defense attorneys estimate it was hundreds.

The legal skirmishes in San Diego court have not drawn a public reaction from Trump, and the Justice Department and Customs and Border Protection agency declined to comment.

It costs the Marshals Service an average of almost $90 a day to house a defendant. In San Diego, space is at a premium, with room for only 815 people at the main holding facility.

To address any space limitations, the Marshals Service has agreements with state and local governments and the federal Bureau of Prisons, as well as contracts with private companies, spokesman Drew Wade said.

Many defendants are unable to make bail because some judges insist they be released to "a third-party custodian" in California, often a relative who is responsible for making sure they return to court. But some family members may be reluctant to come forward if they are in the country illegally, and many live far from San Diego.

Defense attorneys have objected to the requirement.

"It is extremely unusual for courts to require a third-party custodian in misdemeanor cases," said David Loy, legal director for the ACLU of San Diego and Imperial counties. "These are basically federal petty offenses at the lowest level."

Mass hearings on immigration charges were introduced in Del Rio, Texas, in 2005 and spread within a few years to other federal courts on the border— except California. Courtrooms in Tucson, Arizona, and McAllen, Texas, filled with about 70 people a day who pleaded guilty at their first appearance and were typically sentenced to time already served.

The administration said in May that it would prosecute every illegal entry under zero tolerance. But after a backlash over widespread separation of families, officials retreated in June by generally exempting adults who come with their children. Days later, a federal judge ruled against separating families.

In San Diego, each defense attorney is assigned no more than four clients a day and, on most days there are only 10 attorneys, resulting in a cap of 40.

Fred Sheppard, an assistant U.S. attorney, recently said in court that the Border Patrol arrests 90 to 140 people a day in San Diego, implying that many are not prosecuted. (The administration says there has been a "slight uptick" in families crossing illegally and turning themselves in since a large caravan of Central American migrants reached Tijuana, Mexico, last month.)

The prosecutor spoke as the government presented 43 people for prosecution, three over that day's cap. Three men entered the jury box and were told by Gallo that their cases were being dismissed because they had not had a chance to speak with an attorney.

"The system is burgeoning," the judge said.

Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.