Generally for freestyle you want to follow these rules to avoid shoulder injury:
1.) Don't cross the center line of your body with your arm. If you were climbing a ladder you wouldn't ever do that. Freestyle is kind of like climbing a ladder horizontally.
2.) Keep a good rotation around your center line in the upper body. This helps to use your back muscles/lats to do the big work. You want to be sore at the end of the workout in your lats, core and maybe chest. Not your shoulders.
3.) Don't over-extend your arm in reach. Many people end up pushing down on the water they initiate their stroke, this is wasted work and also shoulder strain. You want to as quickly as possible have your hand pulling parallel to your body, which usually means a high, wide elbow in the catch.
This is a course I've been meaning to try but haven't. It purports to reduce shoulder injuries:
https://www.swimsmooth.com
This is the current view on how to initiate your pull:
https://www.triswimcoach.com/high-elbow-catch/