I didn't think about that. This feels impossible.
It involves the keys NPCs carry. You obtain the key, you gain ownership of the house. The way I've been doing that is attaching a script to every key and change ownership of the cell to the player upon retrieving them.
This while simple in method, present some problems. First of all, the beds have ownership set to something other than the cells default ownership. And for things like shops, the items sitting on the counter are under the services faction associated with that merchant. I didnt think it was wise to change ownership of shop items, so I simply added the player to that service faction, make it so those items are free to pick up and not tagged with "stolen".
Then came the problem with the player choosing not to kill the NPC but pickpocket the key instead, or locking picking and gaining the key through the Wax Key perk. While they own the home, the NPC will still have packages to do stuff in the home, hence immersion breaking.
And finally, respawn. Some cells have it where all of their containers are set to respawn and I can't change this in the editor without editing the base object. You know what that'll do if I do.
Edit: It's not *every* key. Only keys to NPCs I deem are "safe". So to speak. Quest related/essential NPCs are left out.