Expert and knowledgeable user Kali lately posted a link to an article which will help you to understand and interpret what you see:
http://www.standardsteel.com/rdpapers/freightcar.pdf. Said article deals with freight car's wheel treads, but the same metallurgical phonema apply to the rail head as well.
Essentially, in my own words it comes done to the rail head's steel changing crystal form/crystalline structure under heat and pressure caused by friction against the turning wheel.
The steel becomes hardened and remains in that state once cooled down again. The hardened spots "stand out" in the continuous elastic beam a rail actually is and since hardened steel is more brittle, it chips and breaks away over time. The damaged spot propagates itself in the direction of traffic and the prolonged hammering and rattling will eventually lead to total failure of the rail by cracking the web and/or loosening of plates and spikes. It is also known to be capable of complete crumbling of concrete ties, as these lack the inherent elasticity and damping of wooden ties.
The photo with the almost completely ground down rail is an extreme example for sure. No engineer would allow this to happen under his wheels. The rail's colour and "liquid flow shapes" suggest to me it was semi-melted and hence became plieable (sp?), instead of it just being grinded away in a shower of sparks like when you use an angle grinder on some piece of steel in a metal workshop.