Image copyright Galicia family/CBS Image caption Francisco Galicia was stopped at a checkpoint in late June

A US citizen has been freed from US immigration detention after three weeks in conditions so dire he considered asking to be deported.

Francisco Erwin Galicia, 18, spent 23 days detained in south Texas, saying he lost 26lb (12kg) in that time.

The detention comes amid a crackdown on undocumented immigrants.

American migration officials are not meant to detain their own citizens, but it appears there were doubts about the authenticity of Mr Galicia's documents.

Mr Galicia was released on Tuesday, less than a day after The Dallas Morning News reported on his incarceration.

Why was he arrested?

Francisco Galicia was arrested with his brother Marlon - a 17-year-old non-US citizen - on 27 June at an inland US Border Patrol checkpoint as they drove to a soccer scouting camp in hopes of landing a university scholarship.

"We're supposed to graduate from high school next year, and we wanted to do something to secure our education," he told the newspaper after his release.

Marlon and other passengers in the car lacked legal migration status and were arrested.

Francisco said he told agents he was a US citizen, and presented them with a "Texas ID, Social Security card and a wallet-sized birth certificate", according to The Dallas Morning News.

"I told them we had rights and asked to make a phone call. But they told us: 'You don't have rights to anything'," he said.

Two days after the arrest, Marlon voluntarily allowed himself to be deported to Reynosa, a dangerous Mexican border city, in order to tell their mother about their whereabouts.

What have border officials said?

In a joint statement on Wednesday, US Customs and Border Patrol (CBP) and Immigration and Customs Enforcement (ICE) defended their decision to hold Francisco Galicia.

"Generally, situations including conflicting reports from the individual and multiple birth certificates can, and should, take more time to verify," the statement read.

"While we continue to research the facts of the situation, this individual has been released from ICE custody.

"Both CBP and ICE are committed to the fair treatment of migrants in our custody and continue to take appropriate steps to verify all facts of this situation."

Media playback is unsupported on your device Media caption In another immigration raid an ICE agent smashed a car window

'Squalid conditions'

During his time in a CBP holding facility in south Texas' Rio Grande Valley, Francisco said he was not allowed to shower and was housed in a holding cell with 60 other men.

They were only given aluminium-foil blankets and were forced to sleep on the floor. Some men had to sleep on the floor near the toilets.

"It was inhumane how they treated us. It got to the point where I was ready to sign a deportation paper just to not be suffering there anymore," he said.

"I just needed to get out of there."

Media playback is unsupported on your device Media caption Justice department says toothbrush and soap 'not required' for migrants

Have other Americans been detained?

A Los Angeles Times report from 2018 found that 1,480 people have been released by ICE after having their citizenship status investigated.

In one case, an American citizen of Jamaican descent was held in immigration detention for more than three years before being released hundreds of miles away from home.

In March, a nine-year-old girl was held for more than 30 hours after crossing from Mexico into California at an official border crossing with her 14-year-old brother as the two US citizens walked to school.

"I was scared," the girl told NBC in San Diego. "I was sad because I didn't have my mom or my brother. I was completely by myself."

Last week, a California congresswoman visiting a Border Patrol crossing centre in Texas found a 13-year-old girl holding a US passport waiting with her mother who allegedly had crossed into the US illegally.

Media playback is unsupported on your device Media caption Taking difficult routes has cost people their lives

What is the legal situation at the border?

On Wednesday a judge in San Francisco ordered the Trump administration to stop denying asylum to anyone who passes through another country on their way to the US. It would effectively end asylum for Central American migrants, who pass through Mexico on their way to the US.

The decision came hours after a judge in Washington ruled that the nine-day old policy could stand. The California's judge's injunction means the policy is put on hold as the courts decide the future of President Trump's policy.

White House spokeswoman Stephanie Grisham slammed the injunction and said the Trump administration would "pursue all available options to address this meritless ruling and to defend this nation's borders".

The decision comes as tens of thousands of migrants wait in Mexico under a US Department of Homeland Security policy dubbed "Remain in Mexico" in which migrants are told to stay in Mexico as they await a hearing in a US immigration court.

According to Mexico's National Migration Institute more than 18,000 migrants have been sent back under the new policy.