Here's an even better article explaining what happened. Mark Joseph Stern lays the blame, as others are doing today, squarely on the "deal" made by a previous prosecutor, Bruce Castor.
Cosby issued a statement trying to spin his release as some sort of proof that he was innocent. The court didn't say you were innocent, Bill. If you try to make public appearances in the future, I'm sure the people outside with signs will explain it to you.