There are some possible reasons. First of all, you might not be ready to perform yet, maybe you had too little practice and therefore you had a panic attack during an actual performance.
Secondly, we are not robots and not computers, so we cannot program ourselves and play without mistakes.
Also we might lose our concentration and make a mistake. There are all kinds of thoughts that come to our minds while performing. For example, I play so well even in that difficult spot and I didn't make a mistake but this is a moment than the mistake happens.
I'm sure every performer would have her own answer to this question. My best advice to you and myself would be just to stop worrying about making mistakes.
Face them with a smile.