We are a social species. This means that we not only live in social groups but we rely on the people around us. This was part of our evolutionary history for a long time.
This means the better we are at working out what other people are thinking, feeling, experiencing, etc the better we can work together as a group and the better we can be at getting a better position for ourselves and not being ripped off by others in the group trying to do the same and also better at helping others in the group (it’s very messy).
So, when we feel pain when others are in pain it’s part of our empathy system and enables us to better understand the other person.
Same with seeing someone else relaxed plus if they’re relaxed then we can feel relaxed because there’s no danger from them.
This is not many that do literally feel pain when they see other hurt.
There are even some who can’t see a movie because it genuine hurt when an actor pretend to be hurt. Others are in the opposite corner, like me. (no, I do not enjoy seeing anybody in pain) I am just saying that I do feel nothing, this is a very valuable thing when you want to help. You can better be concentrated on listening to the hurt person, talk calm, support and just be there when you are not also feel the urge to vomit, pain or even sickness.