There are a few reasons why your toddler might be sleeping in the closet. It could be that they feel safe and secure in a small, enclosed space. Or, it could be that they're trying to avoid being seen by you or other family members. Whatever the reason, it's important to try to understand why your child is doing this and how you can help them feel more comfortable sleeping in their own bed.
If your toddler is afraid of the dark, sleeping in the closet may help them feel more secure. If this is the case, try using a night light or leaving the door open a crack so they don't feel so isolated. You can also try encouraging them to sleep with a stuffed animal or toy for extra comfort.
If your toddler is avoiding being seen by others, it's possible that they're feeling embarrassed or ashamed about something. Maybe they wet the bed and are afraid of being made fun of, or maybe they had a bad dream and don't want anyone to know. In these cases, it's important to talk to your child about what's going on and let them know that it's okay to ask for help. You can also offer reassurance that you'll always be there for them no matter what happens.
Whatever the reason for your toddler's behavior, remember that it's normal for children to experiment with different sleeping arrangements at this age. Just make sure to stay tuned into their needs and provide support as needed.