The problem is that they could conceivably unlock themselves while sleepwalking too. They'd instead need to consent to being locked up by someone else, which seems like a safety hazard to me (fire starts in my house, do I die chained up to my bed?)
All that said, someone with a condition known to be a danger to others is at least negligent if they do nothing then others get hurt.