Mr. Marsh, who suffered a head injury as a teenager, has no one else to look out for him. He has long been out of touch with family members and says he has no friends.

His disability payments are disrupted every time he goes to jail, leaving him penniless on release. He is at the mercy of the South Carolina municipal courts, an idiosyncratic system in which police officers serve as prosecutors, judges are not required to have college degrees, and public defenders are often absent.

Tess Borden, a lawyer with the American Civil Liberties Union, said 139 of the state’s 212 municipal courts have no public defenders available.

The A.C.L.U.’s Criminal Law Reform Project filed a federal class-action lawsuit on Thursday against the city of Beaufort and the town of Bluffton, saying they are violating defendants’ rights. They hope for a ruling that sets a statewide precedent that all jurisdictions must provide lawyers.

Municipal courts, which handle traffic violations and other low-level crimes, are optional for South Carolina cities, which can choose to rely on state courts to hear the cases. They can be lucrative: the state’s 212 municipal courts collect some $20 million a year in fines and fees. Last year there was nearly one municipal case for every nine adult residents.

“Under South Carolina law, municipalities that choose to establish their own courts have a duty to fund public defense,” Ms. Borden said. “Yet the majority of cities and towns flout this obligation, prosecuting poor people without spending a dime on their defense. The result is a grossly unconstitutional system in which lawyers are luxuries available only to those who can afford them.”

It is not clear what entity has the ultimate authority for the state’s municipal courts. Tonnya K. Kohn, administrator for the state Office of Court Administration, said that her office played no role in oversight of municipal courts and that the State Supreme Court was responsible.