I think that the why of people saying this stuff and what to say to respond to it and shut it down are related.
This is certainly a super, super brief summary, but I'd say that there are four major reasons people victim-blame, and often more than one of them is at play.
1) Internalized Misogyny: Even when the victim isn't themselves a woman, misogyny has a long history of using sexual violence and victim-blaming to gain and retain power. Some victims have also internalized this, so even though the belief that their abuse was their fault does them harm, they just haven't had the education, gotten the support or done their own work to realize they have internalized this.
2) Ignorance. It's harder and harder to say that people just don't know better anymore, because the information that victim-blaming is wrong and false is very pervasive, but some people are so ignorant that even when they see that information, they don't believe it, or they believe people who tell them that sexual violence and other kinds of abuse are a victim's fault.
3) Being victims themselves and not having done any healing OR being abusers themselves, so blaming victims as a way to excuse their own abuse.
4) Using it as a way to abuse and control: the initial abuser usually does this, but other people -- like parents -- can do it, too. Secondarily, it's sometimes used to try and protect themselves, like when a parent does this to a child who is a victim of incest by another family member.
I think that the best way to shut this down when it happens is twofold: one, you want to say something, and then two, you want to protect yourself from anyone who victim-blames you as much as you can, like by, when it's a choice, no longer being around them at all, and certainly not sharing anything vulnerable with them again, or until they take serious responsibility, make amends to you, and only if you want to open up to them again.
I'd suggest keeping what you say brief and clear, like, "That's an ignorant and hurtful thing to say," and then following it up with a limit or boundary, like, "And please get away from me and stay away. I don't want to be around you or friends with you anymore." Or, if it's someone you can't get away from, like a parent, tell them it's ignorant and hurtful, ask them not to do it again, and then do what you can to be less vulnerable around them, like no longer giving them information about you they can hurt you with.
How do you feel about all of that?
Never doubt that a small group of thoughtful, committed citizens can change the world. Indeed, it is the only thing that ever has. - Margaret Mead