Sunlight makes them produce chlorophyll.
There is a lot more chlorophyll in plants than carotenoids and anthocyanins, so leaves look green. The chlorophyll is what absorbs sunlight to give the plant the energy it needs to make food out of water and the carbon dioxide in the air.
Chlorophyll is hard for the plant to make. The plant only makes it in places where it will do the most good (collect the most sunlight). Most of the leaves are at the ends of branches and twigs, and cast shadows on the rest of the plant, so the trunks of trees and the branches have little or no chlorophyll. The center leaves in cabbage, lettuce, and celery are also lighter in color, because the plant does not waste precious chlorophyll on parts that get no sunlight.
If you look at a bean sprout, you will see that it is mostly white. That is partly because they are grown in the dark, and don’t get enough sunlight. The plant only produces chlorophyll when enough light hits it to make chlorophyll production profitable.