Have you heard the saying about cliches? Cliches become cliche because they so often true. One of the most popular, "never meet your heroes". What you point out is exactly the reason for that.
The thing about anyone of great celebrity, no matter what they are celebrated for, is that they are also people. And the truth many people miss, there are no good people, there are no bad people, there are only people. Every person does things that are positive, healthy, and constructive. Every person does things that are negative, debilitating, and destructive. Almost every person does a statistically greater amount of one than the other. But in the worst evil you can find in humanity, you can find a redeeming spark. Just the same, in the greatest shining example of the human paragon of virtue is the shadow of hate and destruction.
The problem is, so many people want to tie the great values of what so many figures have offered, whether in arts, science, or sociopolitical development, far too tightly with every aspect of their personal lives, and when they find something they view as evil in that personal life they want to destroy everything else they ever made, see what they offered as tainted by their own evil. Look deep enough in anybody's life, and you'll find things you see as objectionable. That doesn't mean you now have to throw away everything they ever offered, but it helps to see it in perspective.
Thus; Mythic-Bill Cosby is a wholesome Dr. Huxtable-guy who would be disgusted by Real Cosby's serial rape. Mythic-Michael Jackson is a harmless humanitarian who loves children in a platonic, non-pervy way and Mythic-Gandhi was a saintly holy-man who never did anything questionable with female followers and rejected "racism" and misogyny.
So to address these:
Bill Cosby did do much for helping to bring attention to and keep funded educational programs that were threatened by loss of revenue. He also has a long and great catalog of clean, family friendly humor. And I use family friendly to encompass the whole family, not just that it's not objectionable material for kids. It's okay to use those programs, and to watch his shows and movies. Drugging and raping multiple women does not take away from what he's offered.
Michael Jackson has provided as well a long catalog of highly influential music, as well as having helped to provide funding to help in the care of children who are sick, and sometimes even alone. There is no need to stop listening to his music if you enjoy it, nor to shut down any programs he has helped create to treat sick kids just because he may have molested them.
Mahatma (Mohandas) Gandhi did help lead India into independence from the British Empire, in his attempt to help lift the Indian people from poverty imposed on them by harsh and abusive conquerors. Certainly India should not be put back under the control of the Crown and Parliament of Great Britain, just because Gandhi slept naked with, and possibly had sex with, underage girls, including family members.
After all, if you tie all these together and remove the good in order to try to excise the evil, you will remove from the record a significant chunk of art that millions of people around the world still enjoy, not just within the US. You will also dismantle educational and health programs that help to teach and care for kids who can't receive all the help that having rich parents would offer. And trust me, the UK wants India independent from them at least as much as India wants to remain independent.
And another example . . . I'm not going to stop liking the Naked Gun movies just because OJ Simpson killed his ex-wife and her boyfriend. I'll appreciate the good that's offered, and try to avoid emulating the evil.
Another reason though not to tie the good that's done with evil that's done, and try to renounce the good with the evil, is again the fact no person is good, no person is evil. We all do both . . . each and every one of us. Should we then do away with every bit of good we've ever done just because we've done harm as well?