Background/Objectives: Previous research points to the prevalence of insomnia during the COVID-19 pandemic among healthcare workers (HCWs). However, longitudinal studies on its evolution, including the post-pandemic stage, are less abundant, with a special lack of research about possible psychosocial risk factors. The aim of the current study is to analyze the evolution of insomnia in Spanish HCWs from the beginning of the pandemic until two years later, examining the influence of sociodemographic, occupational and psychosocial variables. Methods: This was a prospective longitudinal design with three data collection periods in which insomnia was assessed using the Insomnia Severity Index (ISI), in addition to sociodemographic, occupational and psychosocial (i.e., social support, self-efficacy, resilience and cognitive fusion) variables in HCWs (n = 216) who were in direct contact with COVID-19 patients. Results: High scores were observed for insomnia, with a clear decrease throughout the periods studied (F = 30.198, p < 0.001). An association was observed between insomnia and certain sociodemographic and occupational variables (i.e., work category, p = 0.001; availability of Personal Protective Equipment (PPE), p < 0.001; workload, p < 0.001; worry about self or family contagion, p = 0.002, p = 0.003, respectively). Insomnia had negative relationships with social support (p = 0.014), self-efficacy (p < 0.001) and resilience (p < 0.001) and positive relationships with cognitive fusion (p < 0.001). Interaction effects between the evolution of insomnia and social support from friends (p = 0.024, ƞ2 = 0.34) and between the evolution of insomnia and cognitive fusion (p = 0.047; ƞ2 = 0.25) were found. Conclusions: Social support, self-efficacy and resilience act as buffers for insomnia. Cognitive fusion acts as a clear precipitator of insomnia as well as directly influencing its evolution. Social support from friends also affects the evolution of insomnia. Within the specific circumstances of the COVID-19 pandemic, a long-term effect of social support from friends and a short-term effect of cognitive fusion on the evolution of insomnia was observed. The findings emphasize the need to implement specific interventions to promote the mental well-being of HCWs, particularly in crisis contexts that involve an increase in occupational stress, emphasizing the role of certain psychosocial variables as protective factors.