It’s very clear to me when one of my animals isn’t well - they go off their food, hunch up, look miserable and take themselves away from the others. So, if humans do much the same, I presume the mechanism is likely to be similar. I don’t think that higher cognitive functions need to come into the equation.
I agree that it seems to be inherent behaviour in response to symptoms, but I think the picture can be confused in humans who have the higher cognitive functions to enable us to over-ride our inherent need to rest when sick, and instead to push through, potentially preventing full recovery, and misleading observers into thinking we are not as sick as we actually are.
This has certainly been true for me. Far from exhibiting sickness behaviour to elicit sympathy, I have spent years pretending to be less sick than I am, and as a result being judged able to do more than I can actually manage, to my detriment.