The Shulhan Aruch (Orah Haim 202) writes that if a person drinks olive oil by itself, he does not recite a Beracha before drinking, because drinking olive oil by itself is damaging to a person’s health. The Rambam (Rav Moshe Maimonides, Spain-Egypt, 1135-1204) disagreed, and ruled that one who drinks olive oil recites the Beracha of "She’ha’kol." In light of this dispute, Hacham Bension Abba Shaul (Israel, 1924-1998) ruled that one who drinks olive oil should preferably first drink a regular beverage and have in mind that the Beracha of "She’ha’kol" should cover the olive oil, so that a Beracha would not be required over the olive oil according to all opinions.
In any event, it is clear according to the Shulhan Aruch that one does not recite a Beracha over food which is detrimental to a person’s health. In light of this, we might wonder why people commonly recite Berachot over unhealthy foods. The Rambam maintained that carrots are detrimental to one’s health, and the Gemara in Masechet Gittin states that freshly-squeezed grape juice is harmful, yet we recite Berachot over these foods. Modern medicine, of course, has shown that products laden with sugar or MSG causes great harm, as do many fried and processed foods. We might wonder, therefore, why it is customary to recite Berachot over sugary foods and beverages, or over fried foods.
Hacham Ovadia explained, very simply, that unlike olive oil, these foods taste good. Olive oil is both unhealthy and foul-tasting, and for this reason, one who drinks it does not recite a Beracha. But when one eats unhealthy foods that have an enjoyable taste, a Beracha is recited despite the detrimental health effects.
Summary: One recites a Beracha over unhealthy foods even though they are detrimental to his health, because he receives enjoyment from them. However, one who eats harmful foods that do not have an enjoyable taste does not recite a Beracha.