During which procedure the S-TMSI (SAE-Temporary Mobile Subscriber Identity) is allocated?
Answer could be put as a one-liner, during the Attach procedure.
Going little bit deeper into the details..
At the time of initial attach (so I would say IMSI not GUTI attach, what is the difference? Check here What is GUTI and IMSI attach) procedure, the UE sends Att Req with IMSI to the Network to process the Request. If it's successful the MME will reply with Attach Accept message which contain the GUTI as one of the IE (Information Element).
Based on article IMSI, TMSI and GUTI - how they are created (and 3GPP Specs) we know that GUTI consist from MCC, MNC, MME Group ID, MME Code and M-TMSI.
What is M-TMSI (MME-Temporary Mobile Subscriber Identity)?
M-TMSI represents a TMSI in MME area.
Last statement on allocation topic is left to say that S-TMSI is being created from MME Code and M-TMSI. The S-TMSI represents the TMSI in MME pool area.
During the Attach process MME creates the UE Context and assigns the S-TMSI to it. Later this UE Context holds user subscription information fetched from HSS in Authentication process. The local (in MME) storage of subscription allows faster execution of procedures such as bearer establishment because it removes the need to consult the HSS each time.