Minecraft wiki entry for Beginner%27s_guide, associated text: To actually respawn at the new spawn point, the bed needs to stay put! If you pick up the bed to take with you, then if you die the bed is counted as "missing", and it's back to somewhere near the world spawn.
You also need to have some open space next to the bed, on the same level or the level below -- someplace where you could stand when you respawn. This has to be a solid, opaque block to stand on -- glass, slabs, fences, or other non-solid blocks do not count. If there is no such space when you die, the bed is considered "obstructed", and again, it's back to the world spawn. However, your spawn point still defaults to the bed, if you clear the area out later.
In multi-player, if another player has since used the same bed, your spawn point is also lost.