Sun exposure is sufficiently correlated with so many health benefits that it is almost certainly causative for those benefits – especially lower rates of heart disease. Endogenous Vitamin-D production is just one mechanism/signal of the sun's influence, not the full story, so supplementation of Vitamin-D can't reproduce all the sun's benefits.
And, other than preventing sunburns, the health benefits of sunscreen are suspiciously under-proven, and the potential effects of long-term exposure-to/blood-absorption-of their ingredients under-studied. In another decade or two, the current levels of sunscreen use, and recommendation by expert bodies that should know better, will likely be considered a public health failure up there with "use margarine not butter" or "replace fats with sugars" or "masks don't help against respiratory epidemics".
Use shade not sunscreen whenever possible.