I have a child who used to do that. I finally got his frustration redirected by explaining that hitting anyone was not okay, including himself, and he would be disciplined the same way for slapping himself as he would for slapping anyone else. Then we talked about other ways to release that built up stress - screaming into a pillow, writing an angry note and tearing it up, etc.
I think I would write an email to the teacher and explain that DS does that because he feels stupid, that I completely understand that he was NOT calling DS stupid, that we've spoken to DS and he understands but that I wanted the teacher to know in case it happens again.