Not all of them do - as already mentioned, some people still manage to gain back all the weight. Some have pretty horrific complications, sometimes even death, because they can’t keep to the necessary restrictions after surgery.
It’s very true about weight loss - if it was easy everyone would do it.
I worked with a guy who weighed over 700 lbs. He worked two physically active jobs totaling around 90 hours a week, plus at least two hours a day commuting to a ridiculous “suburb” that was built in the middle of nowhere during the housing boom. He loved food, he loved to eat, but he especially loved feeling totally thanksgiving stuffed all day every day. He had gastric bypass and lost about 400lbs in a year. He was in heaven because he could be bursting at the seams all the time and still lose weight. He stretched his stomach back out and before long an extra large meat pizza was just a light snack and he very quickly gained weight. Just north of 500lbs he injured himself while fishing (!?) and was unable to work at all for long enough that he was let go from his second job and I never saw him again.
Once you get THAT obese (bed-ridden, severe skin folds, can hardly roll over, etc), we’re talking serious eating disorders rather than just lack of discipline. It’s basically the opposite of anorexia. Because you really have to work to get that heavy.
Yes, lack of discipline contributes - a LOT - to becoming obese. But once you’re there: our bodies are programmed to hold onto every calorie we can get because tomorrow we may starve. There are biochemical changes that happen when you get overweight, that make it hard to lose extra weight. And your brain becomes crazy obsessed with food.
And, doctors do tell people they have to lose weight. My father-in-law is 8 inches shorter than I am and weighs nearly as much as I do (yes, I’m obese). He’s got numerous health problems as a result and is still willfully clueless about food.
Surgery does a couple of things. It physically enforces reduced calorie intake (though as noted that can be overcome), but it affects how much you can absorb from what you do eat, and also drastically affects the metabolism (I’ve heard that type 2 diabetes can basically reverse almost instantly, even before you’ve lost more than a couple of pounds). Plus, some of the post-surgery sequelae cause sufficient negative conditioning that it seems likely you’d develop an aversion to bad stuff (read about “dumping syndrome” - that might be enough to get me to swear off sweets and I’m a big-time sugar addict).
Whatever the mechanism is, there’s a strong addictive component to the kind of eating that gets you that kind of overweight (and even my own “mere” level of obesity). Can’t quit the addictive substance cold turkey - imagine being told you had to take heroin every day - but just a little.