Okay, we all know looping over mapping is not possible in Solidity, and we all know how to solve it: add an array or counter to keep track of indices in the mapping.
But this question is about why this is the case. The information of which keys are allowed in the mapping should be somewhere, as it can be retrieved.
And if it's not computationally feasible to allow this in smart contracts, why can't Web3 or similar libraries loop over mappings? They are able to query the full smart contract state with no incurred gas costs. Why can they not deduce the list of keys stored in a mapping?