Because it contains usable energy? Protein (amino acids) have like a million functions, some amino acids are glucogenic etc. Various hormones are proteins, some lipid carriers are proteins, some spike proteins cause worldwide hysteria etc…lotsa functions
If you’re just eating an excess amount of protein the process called gluconeogenesis will derive glucose from it, independent of whether you’re anorexic/starving or not.
The body only needs a certain amount of amino acids for things like muscle repair, immune system support etc.
Think of it as a priority system. If your body has enough energy in the form of fat and sugar, then it can use protein to build muscle or create enzymes etc and if it doesn’t have enough fuel circulating in the bloodstream, then it’s going to want that and it will convert protein to fuel. It’s not just a black and white situation though. Even if you’re starving, it’s still going to use protein for other functions like muscle synthesis, but a lot less than if you’re eating at maintenance or more. Muscle uses a lot more protein than other bodily functions so people who have a lot of muscle drastically increase protein intake
Calories are a measure of energy. It’s the amount of energy required to raise a liter of water by 1 degree centigrade. It’s how we measure the energy content of food.
If you ate pure protein you could still gain weight.
What you are getting into is the thermogenic effect of food and how the utilization of different macros can be different. It takes more energy to use protein than it does carbs. So protein has a higher thermogenic effect.
But your body can only utilize so much protein, the ret is excess.
Others have pointed out the prioritization your body used to select energy sources. The link below has diagrams that depict how amino acids (the stuff protein is made of) can enter the cycle that your body uses to turn carbs to energy.
Also as an interesting side-note that helped me to contextualize this information is how something like alcohol fits into this process. Your body actually cannot convert alcohol to fat. It can only burn it for energy. So, if you consume alcohol, that effectively become the #1 energy priority and carbs/protein/fat move into 2nd place, which can mean fat storage.
Every cell in your body contains protein (which are made of amino acids) but there are essential and nonessential amino acids and our body does not make the 9 essential amino acids we need- therefore we have to get those from food. That is why protein is an essential macronutrient and provides calories/energy.