My kitten did the same thing. It was usually just him going in his sleep. Just like a kid wetting the bed. That could be the reason with your cat or sometimes they just forget exactly where the litter box is.
At night shut him in a room with no carpet But with his litter box, food, water, and a towel to sleep on. Don't let him back on the bed for a couple of months. In the meantime, wash all bed clothes twice. Turn the mattress over. Litter train him. For a while, put his litter box by his food and water. After they eat is usually when they want to use their box. When you see him use his box praise him. Give him a treat. Every now and then pick him up in one hand and hold him in the box. With the other hand move his paws on the litter. Then let him out. Use clumping litter. Clean it every day. (You don't have to throw out all the litter, just the clumps and the poop.) My cousin, a vet, gave me this advice.