As long as you are okay with having them be VERY close together (though separated by walls), this design can work.
(top view)
B = bed
X = wall
O = valid spawn location
OOXOO
OOXOO
XXXBXXX
XXXBXXX
OOXOO
OOXOO
Once the player sleeps in the bed, when they die, they will spawn in one of the valid locations. To choose which one, simply fill the others with blocks using pistons.
Since the bed is inaccessible from everywhere but the top, you can make branching paths leading to other beds.
This is a bit difficult to answer since (without mods) you're limited to the in-game rules of Minecraft, which are very lenient. Even if you where to build a very advanced contraption, someone would still get around it by digging/breaking a hole in the wall and just bypassing any locks.
With that said, Here's the easiest setup I can think of.
Make an Iron Door and a Red Stone Torch. Iron doors require red stone power to open, and will close if there's no power to the door. As such, the door will always be closed. When you come home, place a Red Stone torch in front of the door (to open it) walk inside, turn around and hit the torch again to break it. (which closes the door behind you.)
This is the simplist way to create a "key" assuming no one else knows how to operate red stone.
Side note: Unless you go into some advanced Red Stone or command block scripting, You can't have a "secure" door. The best way to keep a place secure is to keep it hidden. For example, Maybe the door into the house is below the house itself? Maybe the house is inside of a cave that's dark except for torches you've put up before hand? The only way to make something secure without mods is to make it not be seen in the first place.
Best Answer
If you are talking about how they make the functions the mods do themselves, then that is a matter of many, many combines commands. Furniture most likely is from multiple invisible armor stands with blocks on their head. If you put 20/30/40 armorstands in the same place with different block on their head and different head/body orientations, you can basically make a block model without resource packs or actual mods.
Also, the way these creations work is most likely on a fill clock that is constantly powering a set of command (20 times a second) that check for you placing down a block or something, and doing stuff when that action occurs (like spawning in all those armor stands when you place down a certain spawn egg or block that creates the furniture).
But if you are talking about how they put all that stuff into one, two or three commands, then that is call a one-click command block structure spawner. These, when pasted into a command block on any world and powered, will replicate the command block structure the original creators made.
While there are many mcedit filters out there that will do this, the one that will copy the blocks in raw (not modify the structure or add anything) is GentleGiantJGC's mcedit filter.
If you would like to get started in making these types of things, i suggest looking through the Gamemode 4 modules. Gamemode 4 is a way to play MC with many of these modules installed in the world. They already have 35 modules, with things from undead players to extra hearts with heart canisters to using minecarts up and down walls. The most notable module is the custom crafter which is the universal way to craft special items that lots of other modules use to do their own special things and how to create a custom crafter recipe.