What's the purpose of gaps between rails?
The thermal dilatation is a property of materials. This property becomes more noticeable in metals. When the temperature of a metal body increases, its linear dimensions also increase
When the temperature of the railroad tracks is increased by solar radiation, especially in the hours of noon, the rail length increases. If there is no separation between two consecutive rails, the increase in length would produce a deformation of the lines by the action of heat, and of course accidents may occur. For this reason a margin of separation between the metal parts is established, to allow for expansion without deformation.
In conclusion, the separation between the lines of the train, avoid its deformation.
The rails are made up of metal (steel) which expands on heating according to the following equation:
(delta)L = L*alpha*(delta)T
where, (delta)L = change in length
L = length before expansion
alpha = coefficient of linear expansion [/degree Celsius]
T = Temperature
Now, during summers the ambient temperature rises causing the rails to expand. The gap there ensure to compensate the expansion in length so that the rails don't get distorted resulting in an accident.