Because thermodynamics exist. Food is compact nature way of storing energy. If you overeat, then your body will store excess energy in fat. Because it hasnt been all used. If you undereat energy is being used from for but rest of it will have to come from fat. Energy, measured in calories, had to come from something. You poop some stuff out too i would guess.
So calorieswise proteins, carbs, or fat - doesn't matter. This matter when talking about proper diet, person needs protein to grow, fat to syntetise some hormones, and carbs as source if quick energy. For good poop you need fiber too.
You are correct, body uses up energy to process proteins and other matter. It is assumed overall that all of these processes are part of that body upkeep of 1400kcal daily.