My DS could be very silent as a youngster - not speak at all unless he was with people he was very comfortable with - but as he got used to new situations and people he gradually became able to speak.
It does occasionally still happen, when he went up to secondary school we all had a difficult few weeks whilst he settled in, and I had to explain to his teacher what it was and what to do about it ie make no big fuss, don't try and force him to speak, just let him come to it in his own time. Within a couple of weeks he was talking to a couple of classmates, and then all the other children and some teachers, and then by the end of the first half term he was talking to everyone.
I was distressed that it had "come back" and felt dreadful for him, but in reality it had not gone away; what I have learned from that is that it might always happen in situations he finds stressful, and because at the time he is unable to explain what's going on, it's best to explain in advance (either by me saying something, or him having a ready-prepared text on his phone) that it might happen, and what it is.
Most of the time now he just does not shut up, and he'll stand up on stage and speak quite comfortably, so your little one won't necessarily always be as affected as he is now, or will learn ways to manage it. It is heart-breaking to watch, and to think about, I know, but it does get much easier I promise.