Yeah, that's a very good point. This is kinda getting off into the weeds from the original point, but interesting weeds nonetheless :).
This study[0] says that measuring CO2 is not enough, and that indirect calorimetry is the gold standard for measuring energy expenditure (EE).
"Calculated EE based on CO2 measurement was not sufficiently accurate to consider the results as an alternative to measured EE by indirect calorimetry. Therefore, EE measured by indirect calorimetry remains as the gold standard to guide nutrition therapy."
Google says "Indirect calorimetry is the method by which measurements of respiratory gas exchange (oxygen consumption, V O 2 and carbon dioxide production, V CO 2 ) are used to estimate the type and amount of substrate oxidized and the amount of energy produced by biological oxidation."
So getting back to your point, if bacteria are feasting on part of the calories and producing CO2, it seems that it would throw off the results even using indirect calorimetry. At that point though are we kinda arguing semantics? While our microbiome isn't composed of human cells, you can still argue it's a part of our functioning organism. It seems it would be nearly impossible to measure human digested calories vs bacteria digested calories, so maybe the results are close enough. Also, many beneficial bacteria release calories that we can consume, like butyric acid, which further complicates things.
[0] https://www.ncbi.nlm.nih.gov/labs/pmc/articles/PMC5251283/