So, a keto diet is fine. Eating bread every now and then is fine. But, something like a fast food meal consumed with a sugary soda may be particularly unhealthy and may cause you to eat more and crave more similar foods.
I don't know all the mechanisms at play, and I don't think even experts have a really good understanding of how our very complex digestive and metabolic systems (and the bacterial colonies that live in our guts) interact. It's clear that caloric reduction works for weight loss, even if you're eating mostly carbs or mostly fats. Some people report better management of cravings and hunger on different kinds of diets, and the research indicates that a low-fat or low-carb diet results in weight loss at about the same rate (contrary to popular belief about low-carb diets lately).
Source: https://www.washingtonpost.com/lifestyle/wellness/low-carb-v...
But, really, if you run a caloric deficit, you'll lose weight. Cutting arbitrary foods can do it for some folks. Some folks like keto or other relatively extreme restrictive diets. Some folks do intermittent fasting (I've been intermittent fasting for several months and have lost a little over 20 pounds). No matter how you do it, if you cut 500 calories off of your diet, you'll lose weight at a healthy clip.