We don’t know where all new variants come from (Dennehy et al., 2022). That being said, many scientists believe a fair amount of new variants get their big break in people that have long term COVID infections, like what’s been seen in people with compromised immune systems (Dennehy et al., 2022).
Weak immune systems can be caused in certain diseases (e.g., HIV), malnutrition, certain genetic disorders, medications (anticancer drugs and radiation therapy) and temporarily by a stem cell or organ transplants.
More studies are needed, but preliminary data suggests that these types of infections often go on for many months (Dennehy et al., 2022). This allows the viruses to get new mutations over time as they presumably hide and fight the weakened immune systems and develop their ability to infect human cells (Dennehy et al., 2022).
Because the virus population size within persistent infections is not limited by bottlenecks at transmission (small amount of virus particles enter your body to start an infection), the rate of mutation is faster in comparison with what’s seen in the general population, so these types of infections typically generate a lot of new genes / mutations (Dennehy et al., 2022).