I wouldn't call that prosecutor stupid now that I know more, just uncaring about the big picture. That lawyer was suing Cosby in a civil case and he knew he could not force Cosby to testify because that would violate the 5th Amendment. So how do you get rid of that pesky Fifth Amendment? You give him immunity. That way he can say all the incriminating things there are and not end up criminally prosecuted. So it helped that lawyer win his civil case, but it hozed the people who wanted Cosby criminally convicted. The civil lawyer won a 3.4 million dollar judgement against him, of which his fee I'm sure was substantial. So that lawyer made great money. However, it was at the price of letting Cosby get away with rape. Stupid? Not at all. Crooked? You bet. Here's a video explaining it more.