Darkness after sunset is mainly because Earth rotates, moving the local area away from the Sun. As the Sun sinks below the horizon, sunlight must travel through more of Earth's atmosphere and is soon blocked, so ambient light levels drop and night begins. The exact timing depends on your latitude, season, and whether daylight saving time is in effect. In short: rotation plus the Sun being below the horizon leads to darkness, with twilight occurring as residual sunlight scatters in the atmosphere before it becomes fully dark.
