Your elbow will only bend one way, so if you shoulder is truly locked, it should not allow your elbow to fly out. Maybe I'm misunderstanding what is happening, but... the bone between your elbow and shoulder, the humerus, is connected to your shoulder as a "ball joint", actually a ball and socket joint. Where the humerus connects to the lower arm bones, radius and ulna, it's two kind of joints. One is a rotating joint, the radius, and the other, simply put, is a hinge joint, the Ulna, and only hinges in one direction. This combination of joints in the elbow will allow you to "twist your wrist" or rotate your hand and lower arm, but the hinge joint will only "bend" in ONE direction. So, if your elbow is flying out, then your humerus HAS to be rotating (or the rotator joint in your shoulder is moving), meaning that while it may appear that your shoulder is "locked in", that may not be the case. On the other hand, I have a friends whose joints don't do what is considered "textbook". I think you could tie this girl in a knot without breaking a bone...
Anyways... go to this website and look at the joints and how they work.
http://www.innerbody.com/image/skel07.html Sometimes if we know get a greater understanding of how something works, we can understand how to correct what is happening. Best I can do without seeing you or at least a video of your stroke, is guess at what's happening. Look at what Fran brought up. See if maybe your body is interfering with your stroke and causing you to have to move your elbow out to finish the stroke. Still, in order for your elbow to move out, either your humerus has to rotate or the shoulder joint has to move.
Just my take on what I'm understanding from your post... and I may be completely misunderstanding what your saying... if so, my apologies for taking up bandwidth.
Bob