The cassette may need to be replaced because of excessive tooth wear caused by a worn-out/grunged-up chain. Ages ago I used to ride my mtb in really muddy conditions. And in one especially muddy ride (...there was so much mud on the tires that they could barely rotate between the seat stays) I managed to ruin the chain and severely wear the teeth on the freewheel and one chainring. You can bet I learned my lesson - I never rode in extremely muddy conditions again!