Wikipedia contains an interesting explanation of why/how edible mushrooms do this (remarkable) thing, but note the important bit about the TYPE of vitamin D they produce:
Mushrooms that have been exposed to ultraviolet (UV) light contain large amounts of vitamin D2. Mushrooms, when exposed to UV light, convert ergosterol, a chemical found in large concentrations in many mushrooms, to vitamin D2. This is similar to the reaction in humans, where Vitamin D3 is synthesized after exposure to UV light.
Testing showed an hour of UV light exposure before harvesting made a serving of mushrooms contain twice the U.S. Food and Drug Administration’s daily recommendation of vitamin D, and 5 minutes of UV light exposure after harvesting made a serving of mushrooms contain four times the FDA’s daily recommendation of vitamin D. High performance liquid chromatography analysis has also demonstrated the effect sunlight has on mushroom vitamin D2 content.
The ergocalciferol, vitamin D2, in UV-irradiated mushrooms is not the same form of vitamin D as is produced by UV-irradiation of human skin or animal skin, fur, or feathers (cholecalciferol, vitamin D3). Although vitamin D2 clearly has vitamin D activity in humans and is widely used in food fortification and in nutritional supplements, vitamin D3 is often used in dairy products.
Mushroom Sunlight exposure Vitamin D2 content (IU/100g):
Shiitake (with no sunlight exposure: 10 — 100
Shiitake (with sunlight exposure, gills down): 11,000
Shiitake (with sunlight exposure, gills up): 46,000
Reishi (with no sunlight exposure): 66
Reishi (with sunlight exposure, pores up): 2,760
Maitake (with no sunlight exposure): 460
Maitake (with sunlight exposure, pores up): 31,900
Safe sun exposure still appears to be the best way to get your vitamin D, which of course is actually a hormone and not a true vitamin, but some sunny mushrooms sound healthy - and that’s how they make vitamin D pills anyway!