If you compare something like "the food pyramid" diet, but with less calories to surgery I have no doubt the surgery will keep more people at lighter weight after five years. However that doesn't seem like a fair comparison. For one the usual diet that gets pushed to fat people isn't a good diet to being with. Next one requires much more dedication than the other, meaning if you are going through a surgery to alter your body so you can't eat as much, then obviously the adherence will be higher.
Also people who result into surgery are usually on their last legs. Doctors won't give you the surgery unless it is your only option. So if you had to loose weight or die in next year, obviously the adherence will be a lot higher than with loose weight or in 10 years you will have to have a surgery.
Most weight loss diets are fine. They involving eating less food, particularly unhealthy food, and more healthier food. Keto, Paleo, Mediterranean, DASH. It doesn't matter because the differences between these diets aren't anywhere close to the differences between surgery and diets.
If you can find just one 5 year study that shows diet works anywhere nearly as well as surgery I'll change my opinion. But they don't exist. I've looked.
Diets do terribly in long term RCTs.