I studied law at uni for a bit, but yeah that’s basically the issue. Sexual assault cases are always difficult.
In a nutshell, on a moral level he deserves to rot in prison. In a court of law however, due process is everything. Prosecutors fucked that up by granting immunity to Cosby to testify in a sexual assault, he said/she said, civil case. Years later, prosecutors used that same testimony to bring upon a criminal case.
Can’t grant someone immunity in a court of law and then back down. That’s the 5th amendment protecting Cosby.