When there is no sunlight, by definition, there is no "light", so no refraction, hence, black. Space is a vacuum, so, no atoms, nothing to refract the light. When an astronaut is in space looking back at the earth, there is a hazy blue glow, that is the atmosphere, all the gasses in the air refracting the sunlight.