As humans, we are only separated by about ~20,000 years from our hunter/gatherer ancestors. That period of time is extremely short in terms of evolution so although we live completely different lifestyles, our bodies have not changed much.
We crave sugar, fat, and salt because they were healthy back in those days just because of how rare those things were to our hunter/gatherer ancestors. Being able to eat the calorie dense sugar and fats means that we would be able to survive more days without food, improving our overall health. We needed salt to replenish all the salts lost through sweat because humans are built for endurance running (early human hunters would jog along until the prey runs out of energy). The humans who didn’t crave sugars, fats, and salt would not build up enough energy and wouldn’t survive as well as those who did crave them.
Nowadays, the food industry takes advantage of our primitive brain cravings to sell us more food. Normally, a person only eats a constant amount of food. If that was the case, for the food industry, the profits will never increase. They have to make people eat more food to generate profits. Thus, there is a strong incentive to put more sugars, fats, and salt in our foods so we eat more of it, regardless if it was healthy for us.