At worst, Hillary Transue thought she might get a stern lecture when she appeared before a judge for building a spoof MySpace page mocking the assistant principal at her high school in Wilkes-Barre, Pa. She was a stellar student who had never been in trouble, and the page stated clearly at the bottom that it was just a joke.

Instead, the judge sentenced her to three months at a juvenile detention center on a charge of harassment.

She was handcuffed and taken away as her stunned parents stood by.

“I felt like I had been thrown into some surreal sort of nightmare,” said Hillary, 17, who was sentenced in 2007. “All I wanted to know was how this could be fair and why the judge would do such a thing.”

The answers became a bit clearer on Thursday as the judge, Mark A. Ciavarella Jr., and a colleague, Michael T. Conahan, appeared in federal court in Scranton, Pa., to plead guilty to wire fraud and income tax fraud for taking more than $2.6 million in kickbacks to send teenagers to two privately run youth detention centers run by PA Child Care and a sister company, Western PA Child Care.