1. He must be a doctor.

2. He has to be a doctor.
(Are both the same? Is #2 grammatical?)

Those may mean the same. But they both have two meanings. One is that it's obvious that he's a doctor. The other meaning is that he's forced to be a doctor.

You'd need more information to be sure you have the correct meaning.

Yes, both sentences convey the same meaning and imply that the person being referred to is required to be a doctor. Both sentences express a strong sense of obligation or necessity.

In terms of grammar, both sentences are grammatically correct. Sentence #2, "He has to be a doctor," is a commonly used construction to express a strong requirement or obligation. It uses the modal verb "has to," which signifies necessity or compulsion. It is equivalent to saying "He must be a doctor." The phrase "has to" functions as a synonym for "must" in this context.