That's because sunlight helps produce the substance we call vitamin D3. We produce it ourselves from the body's own cholesterol, and sunlight gives that production an extra boost. Vitamin D is an animal-derived, hormonal substance that we don't find in vegetables or fruits. Read more about the role of sunlight in Vitamin D.
Vitamin D is called a fat-soluble vitamin
But it's not actually a vitamin because we produce it ourselves, just like steroid hormones. The vitamin D molecule resembles prednisolone, the active ingredient in the drug prednisone, and a corticosteroid. It's certainly not harmless and not a nutrient.
A vitamin D test determines the concentration of…
A laboratory test for vitamin D will never measure vitamin D. What is measured is the next substance in that metabolism: calcidiol. This substance is often referred to as “25-OHD”. Read more about vitamin D metabolism here.
Similarities between vitamin A and vitamin D:
Both are fat-soluble substances, both found in the liver. The liver is the organ where our body collects excess fat-soluble substances to be excreted in the bile. Both substances are part of a metabolism that is decisive in translating DNA into proteins. A relatively low intake already causes serious disruptions, which can even be fatal. Read here and here about those deadly poisonings.
How much vitamin A and vitamin D do we need?
Because we produce both vitamin A and vitamin D ourselves, we don't need these substances from outside sources. We produce them as needed, and that need is very low. Additional intake causes a disturbance that is absorbed as much as possible by the liver. The substances in the associated metabolisms are primarily signalling substances and not nutrition.