Yes, having optimal vitamin D levels significantly reduces the risk of many cancers. This is well established in numerous scientific studies.
What you may not understand is that vitamin D production is significantly reduced when you are tan or dark skinned. Also, very excessive exposure to solar radiation can increase skin cancer by causing more damage than the vitamin D is able to overcome.
You should also be aware that any health problem is the rsult of the weakest link so there are many other factors that have an influence.