'Sandman', in the sense of 'sleep-bringer', has been used since the middle of the 19th century. My guess is that it refers to the little yellow specks of 'sleep' - not unlike grains of sand - one often finds in the corners of one's eyes on awakening. To explain these to children, parents presumably invented a magical mystery creature who 'delivered' them during sleep.