Perhaps folks with a history of violence or dangerous behavior during sleep should have to lock themselves in or otherwise restrain themselves. Seems like a simple fix. Neglecting to do that before someone is killed could be manslaughter.
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?)
Good points. Perhaps a fire alarm could auto unlock? And the lock could have a different code every night, so it's less likely one can open it without conscientious thought.
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.