"Do you know why they are angry?"
The 吗 is completely necessary. Without it, the sentence would mean "You know why they are angry." But with it, the sentence means "Do you know why they are angry?" The 吗 affects the 知道 as the focus of the question.
Why 他们为怎么生气，你知道吗 Is marked wrong? It more often appear this way in real situation.