I've never slept anywhere as well as on a boat. Even if the boat is moving, the waves are smashing against the structure and it feels like you're in a washing machine it's still the most restful sleep I've had.
The periodicity of the boat on waves is calming in a similar way to rocking on a cradle. Something about the consistency of the motion offers security. I’d guess it serves as an additional equilibrioceptive cue to the sleeping brain that’s sensitive to changes in the environment (e.g. an intruder).