What the difference between "he didn't be a doctor" and "he wasn't a doctor"?
In the grammatical sentence
- He wasn't a doctor
the first auxiliary verb (was) is contracted with not to form wasn't.
That's the way the rule goes: Not may contract with the first auxiliary verb in a verb phrase.
In the ungrammatical sentence (the asterisk in front of it marks it as ungrammatical)
- *He didn't be a doctor
The negative is not contracted with the first auxiliary verb, but rather be is treated as a main verb and Do-Support is invoked to insert the past tense of do as the first auxiliary verb, which is then contracted with not to produce didn't be. This is ungrammatical because be is always an auxiliary verb, and does not allow Do-Support (except in imperatives with Action do, like Do be quiet).
*"he didn't be a doctor"
is grammatically incorrect. I'm not sure what you're trying to express with this. Are you trying to say
"He didn't become a doctor"
Your other sentence,
"he wasn't a doctor"
is grammatically correct.