Because all metal expands when heated. If two railway tracks were to be laid together without any gap they will push against each other when they expand in the day. (This is because of the heat of the sun.) When they cool down at night they will contract against each other and return to their original state pulling against each other. The constant pushing and pulling, due to the change of temperature, will cause the joints between the tracks to weaken. They may also break free from one another, causing derailments of trains, and loss of lives.
Thanks for posting your question on Brainly! I hope this helps! :)