I had a student once who had this. I was the only person at the school he would talk to, but his parents said he was fine at home. The general consensus (among the teachers, not his parents) was that he was autistic, but I had some serious doubts about that, since I’ve known autistic people, and I never got that vibe when I was talking with him. Seeing that this is a thing, I think this is a much more likely explanation.
This was in Japan, so my operating hypothesis was that it was some kind of social anxiety, and that since I was, to some extent, outside of the social system that produced the anxiety, he could talk to me.