Ultimately, cats sleeping in their litter box is going to be a behavioral change or because of an illness. And so, for most house cats that are relatively settled, where there hasn’t been a change to their day-to-day structure, it’s likely to be a medical issue if they suddenly start sleeping in their toilet.
Cats like to feel secure and safe, and when they are stressed out, anxious or afraid they will look to remove themselves from the situation and find a spot where they feel more comfortable.
If your cat is still a young kitten, there’s a good chance they’ve just not figured out that they aren’t supposed to sleep in the litter tray yet. They might think it’s somewhere fun, or just get tired and decide it’s a place for a nap.