The rest of my post got cut off.
On early Shermans (without the cupola), the machine gun was mounted on the commander's hatch ring, which rotated. As such, it could be behind, in front of, or even at the side of the commander. Depending on where h e was firing, he could do it standing in the hatch. Once the cupola had been mounted on the commander's hatch, the TC'd MG was by default mounted on that rear pedestal. It's important to remember that the pedestal-mounted M2 on the Sherman wasn't intended for use as an anti-infantry weapon. As originally-designed, the Sherman had a hull-mounted .30-cal and a co-axial .30-cal for use against infantry; the turret-mounted MG was intended for use as an anti-aircraft weapon, either by the TC or by an allied infantryman on the top deck. In theory, then, unless your tank was the specific target of the aircraft, the operator of the turret-mounted MG wouldn't be exposed to enemy small-arms-caliber fire.
In practice, of course, the crew of the Shermans used the .50 against basically everything that didn't warrant a main gun shell and accepted the marginally higher personnel losses. It's important to remember that some crews dismounted the rear pedestal mount and strapped the gun (or replaced it with an M1919 .30-cal) to the cupola. While this had the effect of better protecting the TC when he was firing, it also massively limited the arcs of fire of the weapon, and especially the sky arc. The M2 was so long that the gun couldn't be elevated sufficiently to meaningfully track airborne targets (the back of the receiver and the TC's body couldn't both occupy the space of the turret hatch opening at the same time).