You ask "why". This should help you understand what is going on with the wheels and the rails.
The same ideas perplexed the early railroads. The first rails were wood. When steel wheels on steel tracks were introduced, men mocked that 'they wouldn't be able to pull anything'.
As we now know, they were wrong. Steel on steel, with the heavy weight makes for an impressive tractive effort [ADHESION], due to the "cohesive forces between the molecules in the steel".
Atomically, the molecules are being pressed together, making an atomic type 'gear' where they are interlocking, thus producing the 'traction' [friction].
Cohesion (chemistry): the intermolecular attraction between like-molecules [wikipedia]
Of course they will slip. But when you have a heavy monster like the N&W Y6b Type [170,000 lbs. tractive effort] steam locomotive pulling coal out of the valleys of West Virginia, there is enormous tractive effort & adhesion between the wheels and the rails.
Traction or friction can be reduced when the rails are greasy, because of rain, oil, or decomposing leaves which compact into a hard slippery lignin coating. Locomotives have a sandbox containing sand which can be sprayed on to the rail to improve traction under slippery conditions.
Also, when the threshold of the cohesive forces between the molecules is reached, they will slip. The slippage is actually a liquefying of the steel at the molecular surfaces. The sand is smashed into oblivion, but this powder adds grip between the rails & wheels by becoming the 'gear' mechanism for the added traction [friction], temporarily, until the cohesive forces between the steel is restored.
"Why is the Weight on Drivers Important?
For each revolution of a two-cylinder steam locomotive drive wheel, torque is applied four times (or at a maximum at four different times per complete rotation). As a result, it is easy for the drive wheels to slip. To keep the steam locomotive from being too "slippery", it is important to have sufficient weight on the drive wheels. For a given steam locomotive, the ratio of the weight on drivers divided by the tractive effort is called the factor of ADHESION. It has been found that a factor of adhesion of around 4 is a good balance of pulling force and engine weight. If the factor of adhesion is too low (3.5, for example), the locomotive will be "slippery"." [STEAMLOCOMOTIVE.COM]