UVB exposure does cause cancer, that much is undisputed [1]. However, with very short exposures following a correct schedule given by a doctor, UVB phototherapy can be an efficient treatment for Vitamin D deficiency in people with certain specific illnesses like cystic fibrosis or inflammatory bowel disease that cause digestive malabsorption of vitamins. This can also be an effective treatment e.g. for psoriasis. The increase in risk seems to be negligible when used like this [2], but for people without these specific diseases a normal Vitamin D supplement is unequivocally safer.
[1] https://www.cancer.gov/publications/dictionaries/cancer-term...