As we commemorate the 50th anniversary of Gideon v. Wainwright, the landmark Supreme Court decision that gave poor defendants the right to counsel, it would be nice to celebrate. That case, taken together with the 1967 decision In re Gault, which gave juveniles the same rights in court as adults, stands for the principle that process matters in our system of justice; when faced with the awesome power of the state, the accused — rich or poor, old or young — must be properly armed.

Two recent books put a damper on the celebration, revealing just how random and impoverished justice can be, and how flimsy the right to counsel. In “Kids for Cash,” the investigative reporter William Ecenbarger tells the story behind a corruption scandal so brazen and cruel it defies imagination. Between 2003 and 2008, two Pennsylvania judges accepted millions of dollars in kickbacks from a private juvenile detention facility in exchange for sending children — girls and boys, some as young as 11 — to jail.

It is a harrowing tale, lucidly told by a journalist with a good eye for detail. The children’s stories continue to unsettle long after the book ends: the 13-year-old incarcerated forthrowing a piece of steak at his mother’s boyfriend; the 15-year-old for throwing a sandal at her mother; the 11-year-old for calling the police after his mother locked him out of the house; the 14-year-old for writing a satirical Myspace profile. Another 14-year-old, an A student, was sentenced for writing “Vote for Michael Jackson” on a few stop signs; she had a seizure while in detention, banging her head so hard she cracked her dental braces.

Mark Ciavarella is the judge who sent away all those children — and several thousand others — in cahoots with Judge Michael Conahan. Ecenbarger calls what took place “a routine and systematic form of child abuse.” After the briefest of hearings — the average length was four minutes — kids were dispatched to detention centers in which the judges had a financial interest. If parents were unable to pay the costs of detention, their children were sometimes held longer. One teenager’s Social Security survivor’s check, from his father’s death, was garnished to pay the costs.