tl;dr risk and benefit is based on skin colour primarily. Pale skinned people need very little sun exposure to get sufficient Vitamin D in most cases while being at much higher risk of skin cancer. For dark skinned people, the situation is reversed (need more sun exposure and are at less risk of skin cancer).
Here’s a recent article and recommendations on the tradeoffs of sun exposure for vitamin D versus the risk of skin cancer: https://www.sciencedirect.com/science/article/pii/S1326020023052949
tl;dr risk and benefit is based on skin colour primarily. Pale skinned people need very little sun exposure to get sufficient Vitamin D in most cases while being at much higher risk of skin cancer. For dark skinned people, the situation is reversed (need more sun exposure and are at less risk of skin cancer).