I agree much with what Tom says here.
The non-layman's explanation that encapsulates a good part of this is described by the biopsychosocial (BPS) model of pain. There might be biomechanical factors involved in the OPs situation but there might be little contribution from those aspects as well.
See:
Aches and Pains | Austin Baraki
Doing a set of the same movement that caused an aggravation if perceived and interpreted by the nervous system to be 'safe' can "re-calibrate" the nervous system's response of what is perceived as threatening essentially de-sensitive the 'perturbation' to eventually reduce the 'pain' / 'spasm' / "guarding"/ "protecting-mode."
The reason why the 'protect' happens on the first set according to BPS theory is ultimately multifaceted. It can be difficult to pinpoint what was the reason for the pain that begins from the squat set, but again, it is likely a combination of factors, the contribution of which might be different on each given occasion that triggered that response.
e.g. as a silly example: the OP might have had a stressful day + poor sleep the previous 2 nights + been holding a postural position for an unusually long time at work earlier in the day (which induced a certain kind of fatigue etc...) + not had his usual time with family and friends over the past month + ate a crappy low protein meal with low nutrient value etc. etc.... compared to his typical routine of having pretty good sleep, moderate stress levels, been at usual social gatherings, had his GOMAD and steak, and moved around at work between sitting and standing with regular opportunities to take his body through many ranges of motion.
You might want to take a look at Greg Lehman's free handout workbook that does a fairly good layman's explanation of numerous BPS concepts and various strategies to improve management of pain.
Also:
Dr. Austin Baraki: The Pain Article