Why are people using diabetes medication to lose weight?

It's been called the weight loss secret for Hollywood stars. When asked about his weight loss on Twitter - Elon Musk credited fasting and Wegovy. Wegovy, Ozempic and Rybelsus are all brand names for the medication Semaglutide. It's a medicine used to treat type 2 diabetes, but it's also approved for weight loss.