It is because when a source of light is moving away from you, the wavelength of that light is made longer.This means that the light from stars, that are moving away from us will shifted towards red (because red has more wavelength), and may shift so far that it is no longer visible at all.
That's why black colour appears even if sunlight is present.