Not that too much can sugar is good for you either, but it's more expensive, so before the advent of corn syrup, less was used.
The sugar is the problem and both the pastries have the same sugar. The homemade one may be marginally better but it's a distinction without a meaningful difference. The problems caused by oddball chemicals used in industrial food manufacturing are less than a rounding error compared to the problems caused by obesity.
In Australia obesity increased while sugar consumption decreased. The additives really matter and have a huge impact on human health--they are not a rounding error, but it was a great marketing tactic on behalf of various food industry groups to vilify sugar while deflecting from the other ingredients that are similarly problematic.
Which are present in home cooked baked goods too.
I know it's not as simple as just "sugar=fat" but the difference between home cooked junk food and industrially cooked junk food is vanishingly small.
In terms of chemistry/nutrition I agree. However there is a huge difference in convienence. Pastries are a huge pain in the ass to make, and consequently I only make two or three pies a year. Store bought pastries are trivial to acquire and gorge on seven days a week.
Sugar is sugar.