This is so that passenger and crew vision can adjust to the condition of light or darkness outside the plane in case evacuation is necessary. Take off and landing are the most dangerous parts of the flight*, and for rescue crews it is helpful to be able to see inside the plane to see if there is smoke or people are still in their seats. Crew can also look out to see if the wings and engines are functioning.
Take off and landing are statistically the most dangerous parts of a flight: 49% of all fatal accidents happen during the final descent and landing phases, while 14% during takeoff and initial climb. Boeing Company (2019)