The source of the problem
The most common cause I've encountered for this kind or problem is practicing primarily from the beginning a piece.
The "mechanical" solution
Beginners tend to learn music by developing muscle memory that is associated with the sounds of that music. When the sound or the muscle memory is interrupted, the performer becomes lost. There are no other memory sources (e.g., knowing each individual note, the harmonies, being able to play by ear) to back things up. Thus, the music must be restarted from the very beginning.
It's similar to traveling to a familiar location when one always starts and end the trip from the same places. If there's a different starting place, or a wrong turn, or the familiar trip is somehow interrupted, one becomes lost unless there's good enough knowledge of what went wrong, the surrounding area, or some other cue to help get back on track.
The starting point to fixing this kind of problem is to practice starting from different places in the music — first with the sheet to help, then from memory.
Suppose a mistake occurs at measure X. First, practice measure X by itself. Then start one measure before. Then start at the beginning of the phrase. Try starting in the middle of a random spot near X. This will force your mind, ear, and fingers to learn to music from many different perspectives, and when done sufficiently, will carry you through even when mistakes are made.
The "complete" solution
In addition to the "mechanical" practice described above, there is also the musical/emotional meaning of the piece. Mistakes — and the difficultly in continuing past them — often stem from an incomplete connection with the feeling of the music.
When a mistake occurs, it is crucial, beyond just drilling the notes, to ask what those notes mean. What is happening in the phrase of which they're a part? Is it climactic? Tragic? Exciting? Is there a specific image or story involved? And what role does this note, chord, or passage play within that meaning? Is it the high point? A rest point? A passing-through point?
These kinds of emotional "through-lines" in music can carry us along even when "surface detail" (like notes, rhythms, dynamics, etc.) eludes us.
Consider that when you speak, you can forget a word, use the wrong word, stumble, forget what you were saying, and the person you're talking to still gets your meaning, because they have a feel for what you were saying. Music is the same. Capture the feel, and know "the story" of the music, and that will sustain you through missed notes.