Prosecuting homeless people for sleeping on the streets when there is no shelter available is a form of cruel and unusual punishment that violates the Constitution, a federal appeals court said this week.

The case stems from two ordinances in Boise, Idaho, that make it a crime to sleep or camp in buildings, streets and other public places. Six homeless people who had been convicted under the laws sued the city in 2009, saying their constitutional rights had been violated.

After years of legal wrangling, a three-judge panel of the United States Court of Appeals for the Ninth Circuit said in a 32-page opinion on Tuesday that Boise’s ordinances “criminalize the simple act of sleeping outside on public property, whether bare or with a blanket or other basic bedding.” The panel added that “a municipality cannot criminalize such behavior consistently with the Eighth Amendment when no sleeping space is practically available in any shelter.”

In their summary of the opinion, the judges wrote, “As long as there is no option of sleeping indoors, the government cannot criminalize indigent, homeless people for sleeping outdoors, on public property, on the false premise they had a choice in the matter.”