First, I must address what you said here:
Because he didn’t mention any doctor before saying “the doctor”.
You can read in another ELL answer that there are in fact other uses for the definite article besides "alluding to things that were previously mentioned." As this Wordnik page shows, the word the has several meanings and usages.
Your example is a tricky one, though. Strictly following rules of grammar, one might think that "a doctor" might be more grammatically correct than "the doctor", but I think the latter is more idiomatic.
Personally, I might use any of these:
- I"m going to see a doctor.
- I'm going to see the doctor.
- I'm going to see my doctor.
I'd be most likely to use the first one when I'm on my way to a clinic or emergency room where I've never been before. And I'm most likely to use the last one when I have a scheduled appointment with my primary physician.
I might use the one in the middle when neither one of those is true. Perhaps I'm going in as a walk-in patient where my regular doctor usually works, but I don't even know if he'll be there today.
As I searched for a definition that might fit his context, I found this one in NOAD:
the (article) informal
used instead of a possessive to refer to someone with whom the speaker or person addressed is associated : I'm meeting the boss
I think that one captures the "I'm going to the doctor" usage rather well. It may not be a personal relationship, but the physician-patient relationship as a whole is understood well enough that the usage of "the" sounds both normal and idiomatic.