Bottom line is, the OP is really asking “Why does everything that’s bad for us TASTE so good?” And the answer is, the things that are “bad” for us are NOT bad for us if they’re consumed in the right quantities and the right proportions. In fact, they’re very good for us and absolutely necessary!
Think about it- sugar, salt and fat are all ESSENTIAL for human survival. Indeed, they’re essential for almost all animal survival. And in a state of Nature, overabundance of those things is almost never a problem. In fact, in Nature, those things can be very hard to come by. So, when God/Nature (take your pick) gave us animals a taste for those things, that was a boon!
Almost every animal has a natural urge to consume and to store sugar, salt and (especially) fat, in anticipation of bad times to come. Bears, for instance, love fat so much that they often gorge themselves on fatty fish skins, while leaving the MEAT of the fish uneaten. When winter comes, the fat they’ve eaten will come in very handy.
As for our human ancestors… well, a caveman who had a craving for something sweet would seek out fruit- which is a very good thing! A caveman with a craving for salt might go to a natural salt lick, just as deer do- and that would be a good thing. And if he had a craving for something fatty, he’d have to kill a buffalo and devour the fat. Again, that’s a good thing.
Our problem in the U.S. today is that it’s VERY easy to get those things now! Salt is mined, sugar is grown and refined, and fat has become a virtual industry. If I want sugar, I don’t have to scour the bushes for berries- I eat some candy. If I have a craving for salt, I don’t jog over to a salt lick, I open a bag of potato chips. And if I have a craving for fat, I don’t have to go hunting or fishing- I just buy a tub of ice cream.
So, we’ve outsmarted ourselves, and the taste buds that used to lead us to do healthy things are now our enemies!