Translation:Do you understand what the teacher is saying?
I don't fully accept that answer. We have never seen 什么 function as anything but an interrogative. If I were to ask, 'What is the teacher saying?', it would be 老师在说什么？I wouldn't need any extra 吗, even though here, too, the 什么refers to what the teacher is saying. So I'm still not clear why it's needed here.
Your example is, basically, "teacher is saying what?". "What" is the main question in it.
This question is "what the teacher is saying, do you understand [it]?". The "do" is why the ma is needed. Without the ma, the sentence translates to "you understand what the teacher is saying" (the "what" is the shen me)
In this context, both 明白 and 懂 have the same meaning of "understanding". When YOU apply the words in your own speech, the difference is that 懂 can be further applied to describe what you know (knowledge) or what skills you have. E.g. you can say 我懂英語 which means "I know English" (whereas when you say 我明白英語 it means "I understand how English works", which is a bit awkward we seldom say things like that), or for skills e.g. 我懂得使用Photoshop, "I know how to use Photoshop", whereas you cannot say 我明白使用Photoshop
I think the difference is expressed in English when we say "I don't get what he is saying" vs "I don't understand what he is saying", In the first expression we are saying that we don't understand the import or purpose of his words, we don't understand what his point is, we don't understand the gist of his meaning. But the second expression can just mean we don't understand the words, because we don't know the language he is speaking.
...I understand what this is saying but not why it's saying it. In particular how the parts fit together--(do you understand the teacher) (is saying what?), or possibly (do you understand) (the teadher is saying what?), but I'm not sure how to join the grammar through understand-teacher-saying