Stainless steel was originally chosen for rifle barrels because it resists erosion better than carbon steel. (Erosion due to hot propellant gases is what wears out a barrel.) The stainless is more heat tolerant in this application. Nowadays, stainless steel is also used due to it's lower maintenance requirements than carbon steel.

Understanding the Context