Ultraviolet radiation from the sun (UV-B-radiation) has both beneficial and harmful effects on human health. It is the most important environmental risk factor for the development of non-melanoma skin cancer, such as basal and squamous cell carcinomas.
The other side of this is that the human body's requirements of vitamin D are mainly achieved by UV-B-induced photosynthesis in the skin.
Sunscreen prevents sunburn by blocking UVB light. Theoretically, that means sunscreen use lowers vitamin D levels. But as a practical matter, very few people put on enough sunscreen to block all UVB light, or they use sunscreen irregularly, so sunscreen's effects on vitamin D might not be that important. An Australian study* that's often cited, showed no difference in vitamin D between adults randomly assigned to use sunscreen one summer and those assigned a placebo cream.
*Marks R, Foley P, Jolley D, Knight K, Harrison J, Thompson S. The effect of regular sunscreen use on vitamin D levels in an Australian population. Results of a randomized controlled trial. Arch Dernatology. 2015;Volume131(4):415-421.