There are several things to consider:
Several decades ago, the “common wisdom” was that fat was bad for you. So, to this day we have plenty of fat-free foods to cater to this. But fat made food tasty, so to compensate these fat-free foods instead have even more carbohydrates - sugars.
The folklore dietary “science” has for the last decade or so been lambasting high-fructose corn syrup as a culprit. First, yes, you’re adding much more sugar. Plus, there’s the concern about how quickly fructose is absorbed into the body vs. glucose, etc. starch carbs enter the blood at an even lower rate. The same folklore says that the bigger burst of sugar triggers a bigger burst of insulin, causing obesity, eventually Type II diabetes, etc.
The alarmists will say all sugars are bad - but obviously, it’s energy your body can use, and like anything you consume, past a certain point it will have less benefit and then eventually a detriment.
As mentioned, some sugars are sweeter to taste - so adding those to a product instead gives the initial taste a bigger jolt, encouraging repeat business. The ideal culprit is the much maligned high-fructose corn syrup.
Sorting out the competing claims is difficult- plus, we’re deep into conspiracy-theory-land by now. “The sugar industry paid to have fat maligned, and bury the truth” and that sort of thing. We’re about the same place we were in the 90’s with smoking…
The short answer is - everything is ok in moderation with a healthy lifestyle. Sugar may be causing obesity, but so is lack of activity. After all, portion control is another issue - the traditional Coke bottle, the little greenish thing, was IIRC only 10oz. One or two were good for the day.