OK, so I've done some research. I'm going to say that both B and D are technically correct, although the deeper you go, the less agreement there seems to be as to "why".
The general rule is that when reporting interrogative questions in indirect speech, in addition to altering the verb tense, you alter the sentence structure to make it a declaration. This would be "D". However, when indirect speech reports questions that originally contained "what, who, or which" + "to be" + a complement, you can switch things around, which would be the "B" scenario.
She asked me which color was best. (Correct)
She asked me which was the best color. (Also correct)
He asked what the red building was. (Correct).
He asked what was the red buidling. (Also correct).
They wanted to know who the tall man singing was. (Correct)
They wanted to know who was the tall man singing. (Also correct)
My teacher wanted to know what the matter was with Mary.
My teacher wanted to know what was the matter with Mary.
There seems to be no academic consensus on why this exception works. Some say it is a purely regional or dialectical phenomenon. (And modern American English might lean towards "what was the matter"). Others believe it is influenced by style, arguing that keeping the "question order" ("what was the problem with Mary") "flows" better in longer sentences. Some authorities say this exception works because "to be" is functioning as a copula (linking verb). Older British authorities such as Fowler's "Dictionary of Modern English Usage" acknowledge the exception, but caution against it. More modern ones such as "A Comprehensive Grammar of the English Language" acknowledge the exception and are ok with it.
Some online discussions also suggest a regional preference. If your teacher is from America or studied there, he or she might prefer B. But I think they're both ok.