My guess is that the code that makes you sleep in that case gets the position of the item, teleports you there and then applies the sleeping animation. When an item is in an inventory, its position is 0; 0; 0