If he was a white European kid, he likely would NOT have been asked this question by his teacher in front of the class. It is up to the administrators to know if their students are legal US residents and deal with them accordingly. If a teacher has confirmed knowledge that a student is an illegal, he/she/it should report the student. A teacher's job is to educate students if they are present in class and mark them absent when they fail to attend.
No, this wasn't a racist question, per se. But it was not tactful, a quality that a public educator should have.
The Supreme Court has ruled that the children of illegals must be educated the same as citizens. For that reason it is wrong for a teacher to be asking about green cards.