You can wear your cap or sleep with your head uncovered. Sleeping with your hair uncovered will likely help it knot up faster, but it will also dry your locs out and can attract lint to your hair. Sleeping with uncovered locs is a bigger concern for people who put products in their hair, though, especially for retwisting. So sleeping with your hair uncovered would work, but you’ll just have to make sure your hair is moisturized.
A great middle ground that lets you sleep with your hair uncovered and helps retain moisture is a silk or satin pillowcase. You still get some friction to help knot your locs, but the material won’t absorb what’s on the surface of your hair.
I hope this helps!