The rails are firmly fixed, longitudinally as well as laterally, with pretensioning in order to minimise stress as they heat up. This is true with ties as much as with a concrete bed.
https://interfacejournal.com/archives/644
"There are a number of ways to increase the resistance of rail to buckling. The first and most common is the use of rail anchors to limit the longitudinal expansion of the rail. Anchors come in a variety of designs, but they all apply several thousand pounds of clamping force on the base of the rail. When applied properly against each side of the crossties, the anchors prevent expansion of the rail in the longitudinal direction."
The general approach is described here: https://en.wikipedia.org/wiki/Rail_stressing
Usually they are joined to a rail with a slant cut or a tongue section at ends, and let ride into the opposing cuts/tongues, IIUC.
The rail can only expand if it can move. If the rail is clamped down tightly to the sleepers, and the sleepers are tightly packed in the ballast, then it just doesn't expand. The only thing that happens is that stress increases / decreases as temperature changes.
The pre-tensioning is only to ensure that the average tension in rail in the course of an average year is in a certain range.