This is explained in A Link Between Worlds. When a person sleeps, their spirit goes to another world called the Sacred Realm. This happens because sleeping people are sent to the world that is most similar to their own.