Hi
This depends on the direct sentence.
In this sentence it is clear that the direct sentence is "All the students did their homework"
So when it is reported it becomes " The teacher said. that all the students had done their homework".
Thank you
Majed