Not everyone answers this way... it's just a normal, conditioned response to the question "how are you?"
How many people do you know that actually say "I'm not fine", no matter where they are, or what the situation was when the question is asked?. Not many, unless they need to vent or complain about something.
Many patients in the hospital answer "I'm fine" if they're not in pain or confused, but it's very normal to hospital patients to say "I'm in pain" or "I feel horrible". They form that "I'm fine" response because they already assume that the doctor knows that there is something is wrong with them...otherwise they wouldn't be in the hospital, right?
So really what the doctor is asking when he says "how are you" is "aside from what brought you here today, how are you feeling?". The normal response to that question...for most people is (yep you guessed it), "I'm fine".