There could be any number of reasons why focus is lost during a performance, and what we always battle against in doing so revolves around the fact that we simply are not very good at using fine motor skills (as opposed to gross motor skills), unless we repetitiously practice those gestures with a full understanding of the deeper processes that perpetuate the composer’s musical thoughts. With this in mind, I’ll ask a few questions and see if that helps you reinvestigate what is happening during your learning process with any kind of repertoire:
How deep is the understanding of the theory behind the repertoire you are playing? As pianists, we have not only the linear motion of the music, but the vertical nature of music to contend with as well. As opposed to a note-by-note approach to learning/performing, there needs to be an awareness of the “shape” or “position” that is being explored at that moment, and how the combination of chords, scales, and arpeggios play into that harmonic position with the fingering you have found to be most comfortable and logical.
With that in mind, are you practicing the passages with awareness of where you were, where you are, and where you are going? One of the toughest challenges is having to be in the moment, but also to be conscious of the immediate surroundings both past and future. That can be quite distracting, and the mind may wander too far ahead or linger too far into the past to be of any good use in the present. One must train the brain and body to limit the amount of peripheral musical vision so as to not be thrust out of musical context both technically and mentally. I often explain it to my student like this… your mind during a musical performance is like a magnifying glass hovering above a large page of newspaper. That glass is exposing a small portion of that page for specific words or phrases to be viewed more clearly while the rest of the page remains unfocused in the periphery. Maintaining the position and motion of that glass across the page is crucial if one is to avoid any mishaps that may be caused by material that lies outside of its window.
Is it the notes or what lies in between? I often have to remind my students that due to the expanse of the instrument from a physical perspective, it is the movement of the body from one place to another that can cause all kinds of mayhem if the gestures are mismanaged or if they are not fully considered as part of the practice mechanism. My students focus so intently on the notes that they forget that the physical movement from one place to another has to be as much a part of the regime as engaging with the notes themselves. Knowledge of how your body is moving through space, how you are shaping your hand to match the correct position once you get there, and even what your eyes are doing at that moment has a large role to play in avoiding any kind of mistakes that may occur because there isn’t enough awareness of what is required during that moment. Have you ever been performing and something about what you just did entered your mind that you never thought of before, and it distracted you away from the task? If so, it is likely a surprise appearance of some musical or technical revelation that was missed during a practice session. Slow practice with deliberate focus on what is happening between the notes can be quite revealing, and it will prepare you enough to diminish the chance that any surprises of the sort will occur.
Lastly, are you mentally diverting too much attention to one thing that takes away from another important component of the music-making process? For example, I notice quite often that my students unevenly divide the attention between the hands, particularly in places where the technical demands of one hand greatly outweigh the demands of the other. I’m not saying it should always be 50/50, because that is simply not how music for the piano works in most cases. However, piano playing is a “collective” cooperation of the hands that needs to be properly gauged so one of the partners isn’t “forgotten” in lieu of the other due to technical complications. Sometimes it might be 60/40. Other times it might be 80/20. It should never be mentally 0/100 or vice versa… I remember a long time ago there was a student playing the F major Chopin etude Op. 10 No. 8 with some difficulty. Several of the teachers got up to view what was happening to help, but few could figure out what he was doing that was causing all the problems. After a few failed suggestions, I asked the student to play just the melody at the beginning with the left hand. Not surprisingly, the student could not play it at all. What this meant was that he was not considering the melody as an important enough component due to most (or all) of the focus being placed on the right hand arpeggios cascading up and down the keyboard. Once he considered the melody as a participating layer, and knew what it was doing, the collective nature of the hands started to improve.
Sorry for such a long post, but I certainly hope this helps you to consider some things in the hopes that your confidence with larger pieces and the minimization of mishaps improves in your music making!