If your premise has characters facing danger somewhat frequently, it makes sense to have someone who can heal around.
Also, with so many unknown space-originating ailments, it's creepy to hear a doctor of high rank say "I don't know what this is or how to fix it." It adds to the stakes of the show.
Stories often have an author-as-character, where the writer(s) use a certain wise character to voice their own opinions.
TOS just merged these ideas into one character.