One of those things only Michael himself really knew.
From the psychological point of view, usually the more expressively one demonstrates power and confidence on the outside, the less confidence there really is inside. So it could also be speculated that Michael possessed the most (natural type of) confidence during the Off The Wall and Thriller days, simply because it seemed so overdone in the following decades.
But after the success of Thriller, as he started to thrive to become an untouchable global pop god, it all became part of the act. So I don't think it can really be analysed by looking at rehearsed performances and promotional stunts, that only give away how confident he wanted to APPEAR (not actually felt).
As Taj Jackson also recently said, Michael was always shy in small groups of people that he didn't know well. He said Michael was most confident when performing, the bigger the audience, the better.
Did certain events (his change of looks, allegations, death threats, tabloid propaganda constantly out to taint him as wack etc) have an impact on how confident he felt in public? Likely. Who would not be affected by that.