The main reason solar lights work is because of the photovoltaic effect. The other name of the photovoltaic cell is a solar cell, which is the part that converts sunlight into electric current. Now, what is exactly a solar cell? It consists of layers and layers of crystalline silicon and other chemicals, which in turn create multiple layers of negatively charged electrons and positively charged spaces.
So when sunlight enters the solar cell, the negatively charged electrons get excited and are pushed in the positively charged spaces. The electrons are then transferred to the solar cell by the positively charged spaces as a direct current of electricity. There the electricity gets stored for usage. Through the entire day, the battery is charged and the sunlight is converted to electricity. But as the evening approaches, since there is no direct sunlight reaching the solar cell, it stops converting the sunlight.
There are light emitting diodes (LED’s) present on the solar panel which turns on when the photoreceptor (light-sensing sensor) detects darkness. Thus, the whole night battery supplies electricity to the LED. This photoreceptor stops working when the daylight appears.