I may be wrong, but I think what happened is Cosby was told in the 2005 case that he would not be tried criminally, therefore when he was forced to testify in the civil trial, he didn't plead the 5th because he wasn't worried about being prosecuted criminally.The prior agreement was apparently collaborated during trial testimony.
“A written agreement from the previous Montgomery County prosecutor, Bruce Castor, stated that he would not criminally prosecute Cosby in the Constand case. Castor testified that while he was district attorney, he promised not to file criminal charges against the comedian if Cosby would testify in a civil lawsuit that was filed by Constand in 2005.
Castor had determined that the prosecution would have trouble corroborating forensic evidence without Cosby confessing to the alleged charges.
Seeking ‘some measure of justice’ for Constand, D.A. Castor decided that the Commonwealth would decline to prosecute Cosby for the incident involving Constand, thereby allowing Cosby to be forced to testify in a subsequent civil action, under penalty of perjury, without the benefit of his Fifth Amendment privilege against self-incrimination,” the court document said.…”
https://www.cnbc.com/2021/06/30/cou...ault-conviction-bars-further-prosecution.html
In a civil trial, you can still plead the 5th, however, unlike a criminal trial, the jury can "assume" guilt if one does.