In a very basic sense it’s true. The first law of thermodynamics must be followed. But it’s a meaningless statement without explaining what people actually mean by calories in and calories out.
When people say calories in and calories out, calories in is meant to represent calories consumed as food, and calories out is meant to represent calories lost through physical efforts (exercise, and basic daily activity).
The problem, however, is that both sides of it are incomplete. There are parts of calories in that will never get absorbed by the body. If the same person consume the same amount of calories in donuts, or alternatively in lettuce, they will almost certainly gain more weight eating donuts than lettuce even if their “calories out” is the same, because a lot of the calories in the lettuce will never be absorbed by their body and will simply exit as fiber in the first place.
Then even looking at the calories out side, a lot of digestion isn’t even done by our bodies. It’s done by stuff like gut bacteria. Someone who has a healthier gut biome will likely not gain as much weight eating exactly the same foods and exercising exactly the same amount as someone who doesn’t have as healthy a gut biome.
Then there are dieting patterns. Most extreme diets, for example, drive the body to enter starvation mode and lower its BMR, so even two people doing the same amount of exercise and eating the same foods, if one of them does it in a way that makes their body think they’re starving and the other does it in a way that does not, the latter will lose more weight since their BMR will be higher.
Calories in and calories out is supposed to convey the idea that all that matters are the calories you’re eating, and the exercise you’re doing. But this is
wrong because the nutritional value of the calories you’re consuming, the timing and frequency with which you’re eating, your gut health, your BMR etc are all also extremely, arguably more, important factors in weight loss.
And all of that is without even considering the impacts of certain types of foods and exercise on your mental health and satiety.
Calories in vs calories out is only accurate in the most basic and meaningless physics sense in the context of weight loss. And yet most people telling others to lose weight offer it as prescriptive advice.