Because atmosphere
Outer space does not have an atmosphere, any object heated by the sun in that space will quickly lose that heat if it moves away and/or into the sun’s shadow (e.g. behind a planet)
Earth does have an atmosphere, so for example when the sun sets and it becomes night time, the location where it becomes night doesn’t become cold immediately.
Latest Answers