When Lorenzo Palma finished serving five-and-half years for aggravated assault in Huntsville, Texas, he was not allowed to leave the prison. Instead, immigration officials ordered the facility to detain him another year and then transferred him to an immigrant detention center in Houston, where it held him for another six months.

"It was pretty bad, the only thing I had in my mind was being deported and what would happen to me because of all the bad things going on in Mexico," Palma, 39, recalled last week. "My mom got sick then because she was very worried about me, and she even had a minor stroke. She was so nervous because my little brother had also been deported."

But on January 5 of this year, Palma was released after the government acknowledged that he was actually a US citizen. Though he legally entered the country from Mexico at the age of six, Palma is a citizen through his maternal grandfather, who was born in the US and lived there for many years. By law Immigration and Customs Enforcement cannot detain or deport American citizens.

"I wanted to kiss the lawyer or the judge, I felt so good," Palma said. "But what I really don't like is that my little brother was deported, even though he's a citizen too."

The story is strikingly common: thousands of citizens have been unlawfully deported or detained by ICE in recent years, according to extensive research undertaken by Jacqueline Stevens, a political science professor at Northwestern University who directs the school's Deportation Research Clinic.

"Recent data suggests that in 2010 well over 4,000 US citizens were detained or deported as aliens, raising the total since 2003 to more than 20,000, a figure that may strike some as so high as to lack credibility," Stevens wrote in a 2011 report. "But the deportation laws and regulations in place since the late 1980s have been mandating detention and deportation for hundreds of thousands of incarcerated people each year without attorneys or, in many cases, administrative hearings. It would be truly shocking if this did not result in the deportation of US citizens."

US immigration courts have recognized some of these errors, adjourning 256 cases between January 2011 and September 2014 after finding that the presumed "aliens" were actually US citizens. Stevens exposed this record after filing a Freedom of Information Act request, and recently obtained case data from October 2014 to February 2016, which she said followed a similar trend.

"Unless you have an unusually thorough immigration judge, which is very rare, or an attorney, you can be a US citizen and not even know you're a US citizen, and abandon claims to be in the United States," said Stevens, who is completing a book about the deportation of citizens. She spoke with Lorenzo while he was in detention, obtained his files from the government and helped his family get documentation to prove his citizenship. She then contacted attorney Andrew Free, who defended Palma in immigration court to have his case terminated on the grounds that he is a citizen.

"I get these types of cases all the time," she said.

The government often makes such mistakes for two main reasons: establishing one's citizenship can be a complex process, and officials can overlook critical facts when working through an enormous backlog of such cases.

There is no comprehensive database of US citizens, nor is there one sole way to prove citizenship, explained Laura Murray-Tjan, director of the Federal Immigration Appeals Project, which bills itself on its site as "the law firm dedicated to immigrants' rights." An individual can either apply through US Citizenship and Immigration Services, assert his citizenship in immigration court, or apply for a US passport — and there are constantly evolving laws that determine an individual's eligibility, she said. Officials often lack the necessary time to examine each case, particularly in immigration court.

"It's already easy for errors to be made, and you layer on top of that the speed at which things are done in immigration court," Murray-Tjan remarked.

Careless mistakes can result in profiling individuals as non-citizens, said Eric Puente, an immigration attorney who works in Dallas. Ricardo Garza, a recent client of his, was held for 36 days in a Dallas jail on an immigration hold even though he is a citizen.

Garza was pulled over for driving while intoxicated, and told police officers that he had US citizenship despite having been born in Mexico. The jail then contacted ICE, which claimed he was only a US resident whose criminal history made him eligible for deportation. ICE then placed a detainer — a request to hold in jail — on Garza.

"Mr. Garza had his social security card and driver's license on him when he was arrested," Puente said. "Had ICE done their due diligence and listened to him when he said an immigration judge ruled he was a US citizen in 1999, and had they looked at their own records, they should have known he was a citizen."

"As attorneys we don't have access to the ICE database," Puente went on. "We have to order our clients' documents from archives, but ICE should have access to those documents."

Garza was fortunate. If he had not found a lawyer, he might have been deported.

"What if Mr. Garza had been indigent and wasn't able to hire an attorney to be able to go to immigration court? The problem is, in the immigration system, you don't have a right to an attorney," Puente noted. "The system is extremely overburdened. There aren't enough checks and balances. An indigent person may not have the resources to hire a lawyer, and then falls through the cracks. Here at the grassroots level we've seen US citizens be deported completely and later on be allowed to come back in the country when ICE realized it was a mistake."

When approached for comment, ICE spokesperson Danielle Bennett wrote in an emailed statements that the agency takes claims of US citizens being improperly detained for immigration enforcement purposes very seriously.

"ICE processes an individual for removal only when all available information indicates that the individual is a foreign national," Bennett said. "As a matter of law, the agency cannot assert its civil immigration enforcement authority to arrest and/or detain a United States citizen. Further, ICE has implemented stringent safeguards to protect against the possibility that a US citizen is detained or removed."

One of the Department of Homeland Security's most notorious citizenship identification errors occurred when the agency detained and deported a four-year-old girl to Guatemala back in 2011. Officials apprehended the girl when she arrived in Virginia's Dulles International Airport after visiting relatives in Guatemala, and they detained her for 20 hours, refusing to release her to her parents in the US. They then sent her back to Guatemala, where she remained until her father hired a lawyer for her return three weeks later. Last summer, the government agreed to pay $32,500 to settle a lawsuit for her wrongful deportation and the stress it caused.

"After returning to the States, [she] began to develop symptoms related to the stress of her ordeal. She began to overeat, throw tantrums, and soil her pants during the day," the lawsuit claimed. "She hid whenever people knocked on the door, she refused to let go of her father's hand, and she became frightened whenever the lights were off at night."

Other deportation controversies span many years, such as the ongoing case of Roberto Dominguez, who was removed to the Dominican Republic for a decade and who is still fighting to prove his citizenship. Dominguez was born in Lawrence, Massachusetts, but immigration officials detained him in 1999 and encouraged him to say he was born abroad for a quicker release from detention, according to a lawsuit he filed against the Department of State. Officials then deported him to the Dominican Republic, where he remained until an attorney successfully helped him apply for a US passport in 2009.

But in 2011 the State Department claimed his passport was "fraudulent." It challenged the legitimacy of his US birth certificate, since Dominguez's mother had also registered his birth in the Dominican Republic.

Andrea Saenz, Dominguez's attorney, affirms that Dominguez's American birth certificate is indubitably his, meaning he has suffered false claims that he is not a citizen for the last 17 years.

"There is no doubt in my mind that Robert is a native-born US citizen and that the US birth certificate at issue in this case is his own and no one else's," said Saenz, who has been working the case for three years. "The government has admitted to us that they have been unable to locate any other real person who can be connected with the US birth certificate at issue in this case."

"I have complete faith that in the end the truth will come out and we will be able to correct the record that the 'real' Roberto Dominguez is the man born in the USA, and that Robert will have his identity and integrity restored to him at long last," she added. "He deserves that much."

When approached for comment about the Dominguez suit, a spokesperson for the State Department said in an emailed statement, "As a matter of policy, the Department does not comment on pending litigation."

Similarly, ICE would not specifically address the cases of Palma, Garza, or Dominguez.