A Honduran transgender woman who was detained in a US immigration facility for seven months despite being granted asylum has been released after a legal challenge.

Nicole García Aguilar was freed from the Cibola County detention facility in New Mexico on Wednesday night, a week after lawyers filed a habeas corpus writ challenging her unjustified and prolonged detention by Immigration and Customs Enforcement (Ice).

García’s ordeal, which included several stints in solitary confinement, highlights the ongoing arbitrary detention of asylum seekers under the Trump administration, which has triggered multiple legal challenges.

“In Ms García Aguilar’s case we forced Ice to review what it was doing to one person, but this is an out-of-control agency that refuses to follow the law unless sued. That’s not how government should operate,” said Kristin Love, a lawyer with the American Civil Liberties Union (ACLU) who filed the petition.

García, 24, fled Choluteca in southern Honduras in early 2018 after surviving a violent attack and receiving death threats which police refused to investigate.

Since a coup in Honduras in 2009, violence against the LGBT community has escalated, prompting many to leave. At least 306 LGBT people, including 97 trans people, have been killed in the past decade, and only 20% of cases have been prosecuted, according to Cattrachas, a Honduran LGBT group.

García travelled overland through Mexico before seeking asylum at a legal port of entry in Nogales, Arizona. She was detained in America’s only specialised unit for transgender people, in the privately operated Ice facility in Cibola County, and was granted asylum by an immigration judge on 9 October last year.

Ice appealed, and García was transferred to the facility’s male unit. After a couple of weeks there she was sent to solitary confinement where she spent nearly three months.

The prolonged segregation caused mental and emotional distress and she lost significant weight, according to her asylum attorney, Tania Linares Garcia, from the National Immigration Justice Centre (NIJC).

“Nicole’s treatment in Cibola highlights what transgender people are going through all over the country,” said Linares Garcia.

According to research by the Centre for American Progress, LGBT people are 97 times more likely to be sexually victimised in Ice custody than non-LGBT people.

Locking up asylum seekers has become a prominent policy under the Trump administration, and the president recently dismissed as fraudsters the thousands of people fleeing poverty, violence and corruption in Central America and Mexico.

Under the Obama administration, nine out of 10 asylum seekers who applied at a legal port of entry and passed the credible fear test were given parole so they could pursue their claim in the community. Under Trump, parole rates dropped to zero until a successful legal challenge by the ACLU in July 2018.

Since then Ice has been forced to give parole to some asylum seekers, but many continue to languish in detention as there is no statutory right to appeal against their jailer’s decision – a legal loophole Love described as “constitutionally questionable”.

In García’s case, Ice rejected parole applications without any explanation of why or how she was considered to represent a flight risk or threat to the community.

The habeas corpus, filed on 10 April, argued that her prolonged detention without access to a legal challenge violated due process.

Two days later Ice said García would be discharged in light of the petition and following a review of her case, but she was kept locked up for five more days.

Denise Bell, an Amnesty International USA researcher for refugees and migrant rights, said: “In general, the only reason to detain someone after they’ve been granted asylum is as a punishment.”

Ice was contacted for comment and had not responded at the time of publication.