All of the tractive effort, or pulling force, of a locomotive is dependent on something called adhesive weight. Because locomotives have smooth steel wheels resting on smooth steel rails, there is very little friction between the two. The great weight of the locomotive causes it to stick to the rails just enough to prevent the wheels from spinning, and it is able to pull the cars. Normally railroads try to keep the friction down to a minimum to save on fuel.
When the rails are wet, a thin film of water can develop between the wheels and the rail, filling the tiny surface irregularities which create friction. This makes for a situation where there is no friction at all, and the wheels will spin and the train will not move forward. Adding some fine sand between the wheels and the rails creates a small amount of friction betwen the two, so the train can move.