Like many things, it's due to a combination of genes and environment. If you have inherited genes which make you susceptible to type 2 diabetes, you are likely to develop the disease if you become overweight or obese. Someone else with the same genes but who doesn't live in an obesogenic environment may never become overweight and may never develop type 2 diabetes. Conversely, if someone has not inherited genes that predispose to type 2 diabetes, they are unlikely to develop type 2 diabetes even if they become obese.
So why do people get it who aren’t obese and never have been? Myself included.