Memory is based on association. Therefore in order to remember something you must make a strong association with something you can already remember. Strongest associations are usually visual but you should try to involve other sense as well to make the associations even stronger. (E.g., if you want to remember to buy toilet paper you can picture a giant toilet roll rolling out of the supermarket door. Then it shouts: "buy me!” Then it rolls over you. There you have visual-aural-touch. Add smell if you wish. So when you next pass in front of the supermarket, that absurd image – because of its absurdity – will flash in your mind and remind you that you need to buy toilet paper). Most good memorizers do these things unconsciously, so if you ask them how they can remember, they usually will not be able to explain. They will just say, “I just do”. Or they will come up with some far-fetched explanation that has little to do with what they actually do.
You can also regard memory as food in the refrigerator. You can only retrieve the food you put there in the first place. People many times complain that they cannot recall things, when the problem is that they never remembered (put it in memory) in the first place. In order to place something in your mind (so that you can recall it later) you must use full consciousness and awareness. Absentmindedness will simply not do.
Keeping these two principles in mind, memorizing music has five different aspects that most people integrate, but if you are having difficulty you will have to treat them separately for the time being.
1. Aural memory. This means remembering how the music sounds, how the tune goes. Repeated careful listening of the piece (and your playing and practicing of it) should take care of this. You can also try to hum it (or sing or whistle) the piece trying not to miss a single note. People with good aural memory and a good ear will “remember” a piece basically by playing it by ear.
2. Visual memory. This means having a photographic memory of the score. For good sight-reading this is essential, since the process of sight-reading is basically memorizing a few bars while you play the previous ones. It is not necessary to be able to retain this memory forever, but you should be able to do it for a few moments if you are going to be a good sight-reader. This also means looking at the keyboard and having a visual image of the sequence of black/white keys needed to play the piece.
3. Touch memory. This means remembering the sequence of touch sensations needed to play a piece. The way to develop it is to play with closed eyes, or in the dark. You must use the black keys to guide you. (This is also essential for sight- reading, since when you sight-read your eyes should be glued to the score, and you should find the keys by touch).
4. Hand memory. This is when your fingers “know” the music. You may even be amazed that you can play the piece and not “know” it. This is a very necessary kind of memory (you cannot play fast passages without it), but it is very unreliable. Because it is based on sequence of events, any mistake and you will have to go straight to the beginning. If you have only hand memory, there is a good chance you will have a blackout in performance. Hand memory is acquired through endless repetitions hands together. And that is why that you must always repeat the correct thing, otherwise you will end up with wrong notes/rhythms/etc. inbuilt in your hand memory.
5. Music memory. This means remembering how the music is built up, how it is structured. This is usually the aspect people pay the least attention to, since it involves knowledge of musical theory and harmony. Take care of this aspect by writing out the harmonic progressions, examining how the melody is built (ascending/descending scales, jumps, etc.). You can also try copying the music (several times) until you can write it from memory. If you don't "understand" the music it will be difficult to memorize, since it will be (to you) just a random sequence of notes.
After you work on each of these aspects separately, you must now integrate all these in what people call “memory”.
Try this method. Put your music book with the piece you are trying to memorize on a desk near your piano (but far enough so that you cannot see it). Now you can look at the score as much as you want, but you cannot take it to the piano with you. Go to the piano and see how far can you play from memory. When you get stuck, go back to the desk, and figure out from looking at the score where you got stuck and why. Then go back to the piano and try again. If you keep at it, and observe the principles above, you should have your piece memorized in no time at all. However this is a mentally intensive process. Mentally lazy people hate it.
The first time you try all this, it will be overwhelming. But if you keep working at it in a systematic, disciplined way, each subsequent piece becomes easier. Then it will be so natural for you to memorize that you will be doing it without even noticing!
This is just the tip of the iceberg.