A federal judge ordered the immediate release of an Oakland man being detained by Immigration and Customs Enforcement at the Yuba County Jail in Marysville, saying the jail conditions put him at a high risk of contracting COVID-19.

U.S. Magistrate Judge Laurel Beeler ordered the Department of Homeland Security on Sunday to release the man so that he can shelter in place with his wife in Oakland, according to the Alameda County public defender’s office.

The man’s attorneys argued in a filing that the government failed to provide safe detention conditions to ICE detainees at the jail. Beeler agreed, saying the man could not meaningfully protect himself while in custody.

“His risk is heightened because detainees at Yuba County jail live in close quarters, cannot practice social distancing, do not have masks, and do not have access to adequate disinfecting and cleaning supplies,” Beeler said in a 20-page ruling.

Attorneys for the man, who has underlying respiratory and mental health conditions, said they were not naming him or releasing details about his case because they feared it would put him at risk of torture if he were returned to his birth country.

The man, in his 30s, was convicted of an aggravated felony in 2011, which cost him his green card and put him on a path to deportation, according to court documents. His wife, a U.S. citizen, attempted to sponsor him for a new green card, but he lost his bid for relief from deportation this year, his attorneys said. The man is appealing the decision.

ICE officials said the agency does not comment on pending litigation.

The man’s release comes amid growing calls for ICE to free detainees who do not pose a threat to public safety, in particular immigrants with health complications who are most at risk of contracting the virus.

“Our clients should not have to contract COVID-19 or die before they can get protection from our court system,” said attorney Raha Jorjani, who leads the public defender’s immigration unit.

The American Civil Liberties Union Foundation of Southern California filed a class-action lawsuit Monday in U.S. District Court demanding a reduction in the number of detainees at the Adelanto ICE Processing Center in Southern California.

The lawsuit argues that conditions inside the facility, including bunk beds that are 3 feet apart and cramped cells occupied by four to eight people, put detainees at risk of exposure to the virus and violates their Fifth Amendment rights.

Health officials have advised people during the outbreak to maintain a physical distance of at least 6 feet.

Thirteen immigrants detained by ICE at the Yuba County Jail and Mesa Verde Detention Center in Bakersfield (Kern County) filed a lawsuit last month in federal district court demanding to be released. They’re arguing that their health conditions put them at risk of dying if they get infected with the coronavirus.

Tatiana Sanchez is a San Francisco Chronicle staff writer. Email: tatiana.sanchez@sfchronicle.com. Twitter: @TatianaYSanchez.