As Hart has said, the lock is part of constructing a home in Hearthfire. It's necessary for creating doors and chests when you're building one of three homes; Lakeview in Falkreath, Windstad Manor in Hjaalmarch, and Heljarchen Hall in The Pale (behind White Run, right around the area where you find Cicero on the road).
A pre-existing home is already safe, which, in this sense, means NPC's cannot enter it. The exceptions are your followers, the home's resident House Carl, or those NPC's that are talking to you when you open the door (because they often get loaded into the house with you to finish the dialogue, but then immediately leave). A pre-existing home is safe, and all of the storage is safe storage, meaning it doesn't reset to any default (empty) state. So, for all intents and purposes, your house locks behind you every time you walk through the door.