We had the same issue with our DD when she was that age, and sometimes it happens now too (at age 7.5)
I have no magic answer, but what worked for us, especially when at school was to inform the teacher(s) of DD's super sensitivities and explain that she can not understand why anyone would be mean to anyone else and that she will sometimes "shut off" if she experiences it. Then everyday when I picked her up from school we talked about how the day was, and if everything went well, etc. The more times we talked about it the better she got at coping with it. What also helped was that she was in a small school and she knew the librarian really well, so when she saw something that disturbed her or she couldn't understand she would go and talk to the lib. about it, and the lib. would help her understand it, and since she worked at the school, she would then take care of it from a disciplinary side.
There have been times when DD just went up to the person who was unkind and told them to stop and asked why they thought it was ok to be mean! (I was amazed she did this, but she said she really was trying to find out why they thought it was ok. Luckily, they were so shocked that someone asked that they weren't mean to her in response.)