Bruce Castor, the former District Attorney, had given testimony that he believed the evidence he had at the time insufficient to convict Cosby and told Cosby that he would not charge him; Cosby was then compelled by subpoena to give his deposition in a civil suit filed by Andrea Constand, the victim in the criminal case. Castor was defeated for reelection because of his declination to prosecute Cosby. His successor charged Cosby and obtained a conviction with the civil deposition as key evidence. The Pennsylvania Supreme Court, rightly it seems to me, ruled that that was government foul play which denied Cosby his due process right to a fair trial.
Aside--Castor was the dope who defended 46-1 in his second impeachment trial in the U.S. Senate with an infamously discursive, nearly incoherent opening statement.