Actually when an UE attaches to a network it can send either S-TMSI (in case of second time attach). Since S-TMSI is 5 bytes long (MMEC+ T-MSI). If UE doesn't have any stored S-TMSI then UE sends a 5 bytes long random value. If UE is sending S-TMSI then it helps to eNodeB to forward "Initial Ue Message" to appropriate MME.
If UE sends random value. It means eNodeB perform load balancing to send "Initial Ue Message" to the MME which is decided by load balancing algorithm.
I would like to share a Use case.
Suppose an UE went to RRC idle state. In that case, MME maintains Ue Context for some period of time to avoid creating a new context for every attach and lot of signalling message exchange in core network. For that purpose MME run implicit detach timer. Once the timer gets expired MME releases the context in the core network nodes.
It's my personal thoughts that something is also done at UE similar to MME. which decides either UE should sends S-TMSI or random value.