I recall a demonstration of a dog that could count up to n, where the trainer threw a bunch of practice dead animal dummies into the tall grass some distance away and gave the command to fetch. Each time one was returned, he repeated the command.
If the number of objects that were thrown was ≤n, then when the next (excess) command was given, the dog would walk around the seat and sit, indicating "I'm done with that, ready for next command" without going out and doing any searching. If the number of items was larger than the dog could count, then he would head out to search for more, even though there were none present.
Being able to remember how many prey animals are hidden saves the futile work and also increases confidence that you got them all. How much extra time would you spend working an area just to be sure? It also means they can calibrate their idea of how well the prey hides, rather than supposing a certain amount of work is good enough. This saves work in general, when deciding if an area is finished.
So, imagine an evolutionary arms race where prey animals can hide, burrow, or whatnot, when they see the predator coming. How much work they spend digging deeper or hiding better can vary depending on strategy, if they are making the predator work harder as well and waste work and waste time. Knowing how many are hiding will cut out that game and give them an advantage.
Perhaps the mental capacity to count to n increased a bit at a time, until it somehow reached a general point where instead of 7 or 9 they could handle on the order of hundreds, because the mechanism had an increment/decrement feature and internal state.