It's also useful in learning from the mistakes of others, and stilling our anxiety that bad things can happen to us, too.
It's related to the cognitive bias called the "just world theory." It's what makes people blame victims. Sometimes more appropriately than others, and our conscious is more "shocked" the "less culpable" the victim is. And why people get more upset about bad things happening to animals than most anything else. Even children because of the assumption the parents or the state is partly at fault for not protecting them.
When a child molester is beaten/killed/raped in prison, people don't get too upset. Well he did bad things. Had it coming. Still totally the fault of the guy who attacked him! But it's a Just World when bad things happen to bad people. Don't molest kids and you won't be thrown in prison and attacked. Sleep softly.
When someone associates with thugs, and the thugs turn on him and beat or kill him, well, don't hang out with thugs and it won't happen to you. Just World. Sleep softly.
When a man is walking through a dark alley at night carrying a bunch of cash and gets robbed, well, that was kind of dumb. Totally the fault of the robber! But yeah don't do that and you're less likely to get mugged. Don't leave valuables in plain sight in the car, either. Lesson learned. World's still kinda just. Be wary, but you can still sleep softly.
When a woman is raped after going out wearing a short skirt, maybe drinking, well that's totally the fault of the rapist. It's complete bullshit that a woman can't feel safe wearing what she wants and having a good time. But there's a still a lesson to learn to help you avoid the same fate. She did put herself in that situation, after all. Maybe don't party so much, bring friends, watch your drink. The world is not just, but maybe you can protect yourself.
When something happens to a kid, what the fuck man?! The kid has no agency, there's nothing he could have done to "deserve" that or could have avoided what happened to him! But...where were the parents? Where were the teachers? CPS? It is an unjust world where anyone would hurt a child. But maybe you can learn a lesson about protecting your kids in this unjust world...
But when something happens to a defenseless animal...my God. Go John Wick on their shit. There is no justification, there is nothing the puppy could do to deserve its treatment, there's no way it could defend itself, there's no one who "should" have been looking out for it. Sleep with one eye open because there are monsters in this shithole of an unjust world.
And I'm not saying any of this is good or correct! It's a cognitive bias! But it's natural and hard to overcome.