Cities can’t make it a crime to sleep on a public street or sidewalk when no homeless shelters are available, a federal appeals court ruled Tuesday in a case that could affect so-called “sit/lie” ordinances in San Francisco and elsewhere.

The constitutional ban on “cruel and unusual punishment,” under the Eighth Amendment, prohibits “criminal penalties for sitting, sleeping, or lying outside on public property for homeless individuals who cannot obtain shelter,” said the Ninth U.S. Circuit Court of Appeals in San Francisco. The state, the court said, “may not criminalize conduct that is an unavoidable consequence of being homeless.”

The 3-0 ruling reinstated lawsuits by homeless people challenging ordinances in Boise, Idaho, that made it a crime to sleep on a sidewalk or to use any sidewalk or public property as a “camping place.” The court’s decisions apply to federal cases in nine Western states, including California. Tuesday’s ruling will become a binding precedent unless it is successfully appealed.

“Our hope, not just for Boise but for cities like San Francisco and cities across the country, is that it causes them to take a look at the laws they have on the books and have conversations about how to stop relying on those policies,” said a lawyer in the case, Eric Tars of the National Law Center on Homelessness & Poverty.

“Our real goal is not to protect the right of people to sleep on the streets,” Tars said, “but a conversation about how we can address the core of the problem, that people don’t have a place to sleep.”

Advocates for the homeless were joined in the case by the U.S. Justice Department, which filed arguments in the Boise case in 2015 saying laws against sleeping on public property, when no shelter space was available, unconstitutionally punished people for being homeless. The filing was issued by President Barack Obama’s administration and has not been withdrawn by President Trump’s Justice Department.

The Justice Department arguments were also a warning to communities throughout the nation that the criminalization of homeless camping should be discouraged. Many communities, including Oakland and San Francisco, still take that as a guideline even while they have anti-camping laws on their books.

While the court said a city could not outlaw sleeping on a sidewalk at all hours, it was less clear about partial bans, like the ordinance approved by 54 percent of San Francisco voters in 2010. That made it a misdemeanor to sit or lie down on a public sidewalk, or on a mattress or other object on a sidewalk, between 7 a.m. and 11 p.m.

Without referring directly to the San Francisco measure, Judge Marsha Berzon said in Tuesday’s ruling that a city’s ban on “sitting, lying, or sleeping outside at particular times or in particular locations might well be constitutionally permissible.” She did not indicate whether a 7 a.m.-to-11 p.m. prohibition would be considered a “particular time.”

In a followup measure, 52 percent of San Francisco voters in 2016 approved a 24-hour prohibition on putting tents on public sidewalks. But before enforcing that ban, officials would have to offer the homeless person shelter and, if available, a bus ticket to another city where a friend or relative could provide housing.

That measure would not violate Tuesday’s ruling, which said cities that made housing available could penalize conduct by those who refused to accept it. But the court said an ordinance that flatly prohibited sleeping on the sidewalk could not be salvaged by a Police Department policy — like one announced by the Boise police chief — to enforce it only when housing is available.

Such a policy, Berzon observed, “could be amended or reversed at any time.”

John Coté, spokesman for San Francisco City Attorney Dennis Herrera, said Herrera’s office was analyzing the ruling to see whether the local ordinances fit the court’s standards. “Aspects of this ruling are already reflected in the laws we have on the books,” he said.

San Francisco issues citations for at least 14 laws prohibiting camping or resting on the streets, but since the Justice Department took its position against criminalizing homelessness in 2015, the number of citations has dropped by about 50 percent to about 10,000 a year, according to the San Francisco Coalition on Homelessness.

That’s still too many, said the coalition’s director, Jennifer Friedenbach.

“Moving people from place to place, and citing them under these laws, does no good and it just makes it harder to get off the street,” Friedenbach said.

She and other homeless advocates around the nation have said for many years that, instead of criminalizing homeless people, cities and counties should simply provide enough housing, drug or mental rehabilitation, and shelter for people depending on their needs. Proposition C, a November ballot measure in San Francisco that Friedenbach helped craft, would tax businesses $300 million a year to raise money for homeless programs.

Alameda County homeless-aid officials were also examining the ruling to see how it might affect the way they manage street populations, but policies throughout the county already emphasize shelter and services over criminalization.

“People may be taken to task for things that are illegal, like prostitution or possessing stolen goods, but they’re not really being cited for camping,” said Elaine deColigny, executive director of EveryOne Home, the county’s main homeless-aid coordination agency. “There are camps that are so dirty or vermin-infested that they have to be moved so the sites can be cleaned, but the intention is always to offer people other places to go, like the Tuff Shed locations, or programs.”

Bob Egelko and Kevin Fagan are San Francisco Chronicle staff writers. Email: begelko@sfchronicle.com and kfagan@sfchronicle.com Twitter: @BobEgelko and @KevinChron