Imagine an animal that requires some substance, but that substance is scarce. Say, a mountain goat that needs salt, but lives in mountains where there’s hardly any around, unlike the seashore. In such an environment, it’ll need all the salt it can get, and natural selection will favor those goats that find salt tasty, since they’ll seek it out.
Obviously, it’s possible to have too much salt in one’s body, so ideally there ought to be a biological function that switches off this craving for salt. But in practice, if salt is that scarce, there’s no such thing as too much salt, so the mechanism that switches off salt’s tastiness can be horribly miscalibrated and still not be selected against.
Sometimes, natural selection can be more subtle: say there’s a species of monkey that requires ascorbic acid in its diet. The obvious evolutionary solution would be to favor those individuals who have a taste for it. But ascorbic acid tastes bitter, the same taste as a lot of things that can kill the monkey. On the other hand, ascorbic acid is also found in fruit, which also contain sugar. So maybe evolution favors those individuals who like sugar, because they then seek out fruit and get ascorbic acid as a side effect.
Now fast-forward a million years or so, to where these monkeys have developed agriculture. What do you think they’re going to plant? Well, the ones that grow best, actually, even if they don’t taste all that good. But surely they’ll go to some effort to make the really tasty ones grow as well. And once they succeed, they’ll preferentially keep planting the tastiest ones they have. In short, they’ll be breeding plants for higher sugar content.
Fast-forward a few thousand more years. By now our monkeys have pretty much figured out the whole agriculture thing. They also have trade, and engineering, and other cool stuff. They’ve managed to grow plants with many times more sugar in them than the natural varieties from which they started. Not only that, they’ve also figured out how to extract sugar from plants, purify it, and add huge amounts of it to other foods. And the foods that have more sugar in them, being tastier, sell better than the ones without, so the marketplace rewards this process. The person who can grow a lot of sweet fruit cheaply gets rich.
And after a while, things get to the point where a previously scarce commodity becomes so common that it’s quite easy to get too much of it. Like Twinkies.
This, I think, explains why doctors and dieticians keep having to tell us to cut down on the stuff that tastes good: sugar, salt, fat, etc. We get too much of those in our diet because they taste good, and we’ve set up a system to deliver a lot of the good stuff at a low price. We crave it because it used to be scarce. And it’s now plentiful because we crave it. It’s a self-reinforcing feedback loop.