If he is acting well at home, his behavior seems to be volitional/premeditated at school.
One possibility for this is- he wants to seem autonomous in front of his peers. Another one may be - something could of teased him about something and he does not want his family to see it.
Children generally act out as a result of 1) power struggle 2) revenge 3) sense of inadequacy and 4) attention seeking
It would help to know if anything had transpired around the time when he started asking that you don't come to his school. Anything either at home, school or elsewhere that could of become the trigger.
Of course, there does not have to be a specific trigger. It may be his desire for self sufficiency.
When he's at home, you could engage him in play where he pretends that he's at school and you're the teacher. You can ask him some open ended questions such as: How is school going for you, are there things that you like more than others/what are they, what would you like your parents to know about your day here, what may be some things you'd want them to see you do, etc.
You may also rather than pretend to be the teacher use some of his toys w/ him to portray the same concept. He could instead of playing himself at school use a toy of his for that as a character and you can use another one. You don't necessarily have to pretend play to be the teacher. You can switch to being one of his peers to see what sense of disclosure he would feel more comfortable with when speaking w/ an adult or child (even during pretend play)
This info is just speculative to address your inquiry about what may be wrong. If anything else comes to you as far as other observed behaviors/symptoms, feel free to reply as this platform in intended for Q & A purposes and I'm going by what you've shared so far instead of assessing the child face to face. Thanks.
do you need any further assistance? Thank you!