The solution is to memorize "the big picture," not just which note comes after which. This is why it's easier to memorize a story in your own language, which you understand, than a string of words in an unknown language.
I'm guessing the Pathetique example is just an example and not the perfect one, because the similar sections there are only a few bars long, are immediately next to each other. I've had problems in the past when the similar sections are bigger and farther apart, like if they're actual formal sections of the piece, like say if the structure is "A, B, A1, B1." If all these sections are dozens of bars long then I forget where I am and wind up laying "A, B, A, um B, wait I'm in an infinite loop."
The best tool is analysis. In the beginning of the Pathetique...

... the "story" of the first 8 bars is "Starts in C minor, cadences in C minor." If we expand to look at the first 16 bars, the story is "Starts in C minor, ends up in the dominant, G. How does it do this? Well, in the first phrase, working backward from the ninth bar, we set up the return to Cm with a dominant 7th chord, G7. We set that up in turn with the diminished vii of G, an F#dim7, which lasts just half a bar. But when we repeat this phrase, we stretch that F#dim7 to a full bar and then the subsequent G has been tonicised to the point that it is the resolution rather than a dominant."
(Actually, looking at the even bigger picture, we're right back in Cm by the bar after the ones that are pictured here. So the real story is just that the entire cadence has been streeeeetched.)
Or, in my bigger problems with large formal sections, the solution would be a formal analysis, which often brings in harmonic analysis as well: "Look, the first B section has modulated to the relative major, but the B prime will be in minor. So the A prime section ends in a way that keeps us in minor."