Pump shafts are protected from thermal expansion through the use of expansion joints or flexible couplings. These components allow for movement and accommodate the expansion and contraction that occurs due to temperature changes, preventing damage to the pump shaft.