Gapless railroads have their joints welded together to reduce noise. The lack of a gap between rail sections also reduces wear on both the track and the wheels. However, because the weld essentially produces one very long track, the individual sections have no room to expand as they get warm on hot days. What prevents the track from warping beyond usability? (Yes, I have heard of tracks warping beyond safety margins on extremely hot days, but I'm wondering about just normal expansion between normal weather extremes.)
What I found looking a many web sites : The continuous rails are usually in 1/4 mile ( USA) lengths made by welding together standard rails .They are hydraulically pretensioned for a particular average temperature/length depending on location ( in cold weather construction the rail may be heated to increase length). They require very good roadbed and they are firmly anchored to it so that the thermal expansion/contraction strain is held at each cross tie ( avoiding a cumulative effect of a few feet of movement at the 1/4 mile joint ). So they have a tensile strain that is greater in cold weather and may go negative in very hot weather. And, some railroads will make welds at the 1/4 mile joints.
The tracks are preheated and welded at a calculated temperature (that depends on the local weather) at the time of installation.
When the track cools to the ambient temperature, this leaves a tensile stress in them. This tensile stress increases on colder days, and decreases on hotter days. As long as the stress remains tensile there is no warping.
On extremely hot days the stress may become compressive. This can lead to buckling of the rails.
To take it back to the basic engineering principle: a change in temperature of something changes its stress-free length. That is, the length it would be if there was no stress on it.
For gapless rails (I'd call them Continually Welded Rails or CWR in the UK), the position of the rail is restrained by the connection of the rail to the sleeper or the slab below it. So the length is unable to change.
If you change the stress-free length without changing the actual length, you create stress. If your rail has got colder, it wants to get shorter, and this causes tensile stress; if your rail gets hotter it wants to get longer, and this causes compressive stress.
Failure occurs when the rail supports can't provide enough restraint against this tensile or compressive stress. On curved track this will manifest itself as the curve radius decreasing under tensile stress / cold weather, or radius increasing under compressive stress / hot weather. For a straight section of track this usually only happens under compressive stress / hot weather, where the track will buckle, snaking left and right, which makes the path of the rail longer, hence relieving the compressive stress.
So, what prevents the track warping is friction between the track and its connection to the sleeper, and friction between the sleeper and the ballast. When too excessive a temperature change occurs, the failure point is normally the friction between the sleeper and the ballast.
Note that as per user190081 and blacksmith37's answers, the stress-free length at installation may not be the distance between sleepers, as the rail may either be mechanically stretched or heated. This is as failure in hot weather is far more of a problem than failure in cold weather, so a distance between the sleepers equal to the stress-free length at a relatively high temperature makes failure less likely. There is obviously a limit to this though, as failure at cold temperature extremes is still physically possible.