When my hen Bea was sick she wanted to sleep in the nesting box for some reason - so I let her. I figured since I didn't know how long she might be with us that I would just let her do her own thing and be comfortable. She never once soiled the nesting box at night. She is healthy again and now roosts back on the perch. I have another hen that is molting right now and she wants to sleep in a nesting box too, so I let her - and she doesn't soil in there either. I wonder if it's a little bit less stressful laying all snug in a box rather than hanging on to a perch all night? Also I wonder if they know instinctively not to make a mess where they lay? I've introduced pullets to the flock and they try to roost on the lip of the boxes and poop all over - so I did shut them out at night.
Also for the first time ever I found 2 eggs laying under their perch the other morning - so I know they did lay during the night. But I think it was because they had to lay an egg earlier in the day while they were outside free-ranging, but were too busy to come in and lay where they were supposed too, so those little stinkers couldn't hold it in any longer.
It seems that most of my hens lay before noon, and usually the ones that need to lay an egg while they're out free-ranging do go back in the coop to lay.