It is not uncommon to get pain in the shoulders when doing the bench press. Typically, this is due to overuse especially when doing the bench press in exactly the same way and with the same equipment for a long period of time.
Very often the injury that causes the pain can be found in the rotator cuff muscles. These muscles may be over-stretched especially those on the back of the shoulder as you push the barbell up as high as possible. Thus, the key to prevention of such injuries is to be sure that you strengthen the muscles on both sides of the shoulder joint.
This includes the muscles on the back of the shoulder, mainly the infraspinatus and teres minor, which are the key muscles involved. The major muscles also involved include the middle trapezius and rhomboid. However, these muscles are typically much stronger and rarely get injured to the extent that the smaller rotator cuff ones do.
Equally important in prevention of shoulder injuries is to do other forms of bench presses. For example, use a neutral grip with dumbbells. In this case, the palms face one another as you extend the arms directly up above the chest. Do exercises such as incline and decline presses and front arm raises.
Also important is to use a lighter weight and press it up above the chest on the first rep, above the navel on the second rep, and above the neck on the third rep. This puts stress on the muscles at different angles so that they can respond with more all-around development of the shoulder muscles.
Some of the better exercises to develop the terres minor and infraspinatus include the reverse fly, bent-over dumbbell row with the elbows kept close to the sides of the body, bent-over barbell row holding the elbows out to the sides, and high cable pullbacks keeping the arm level with the shoulders as you pull the elbows back.
For more information on these exercises and how they should be executed see Kinesiology of Exercise. Not only are these exercises illustrated with photographs but they have detailed explanations not found in other books.