Complexity of the food source is key.
The same amount of calories in sugar, olive oil, meat or chickpeas result in completely different absorption rates in the gut.
While sugar will be immediately dumped to the blood stream, chickpeas will take hours to digest until all the sugars become accessible.
The body needs to expend calories to access the calories in food high in fiber.
Don’t forget about the varying responses of your gut microbiome to different foods. Some calories are easier to access for your body, because your gut microbiome has been inherited/adapted to them since early childhood.
Some foods trigger a strong sugar spike in one person, while it does nothing in the next.
It’s way more complex than the simple equation of calories in = calories out.