It happens at periods where on the one hand the child realizes they are independent but craves the security of the adult.
Anxiety of being "abandoned" by parent ie you as the adult represent the adult that left and they don't want you to leave too.
Helicopter parents at home that don't allow child to have his personal space and therefore he doesn't know what to do with himself when he is given the freedoms and gets afraid.
It can also be an irrational result of having actually been left alone and when child couldn't find parent got scared and now won't let them out of his sight and by default that applies to you too.