Musical memory comes in two flavours: unconscious (muscle) memory and conscious (mental) memory.
Muscle memory comes with repetition and can prove to be surprisingly long-lasting - provided it has had sufficient reinforcement over time. It's something that gets ingrained every time you play a piece - provided you know it well enough to play it without errors every time.
Consicous memory consists in knowing what you are supposed to play in musical terms and being able to play it whenever necessary.
Whenever you try to memorise a musical fragment, it will fall in one of two broad categories:
a. melodic shape
b. standard pattern
I'll address standard patterns first, since they provide a form of musical shortcut. A standard pattern is a musical fragment that is common to many compositions and stems from the rules of chord or scale construction. Thus, standard patterns will include chord forms, chord changes, arpeggios, scalar runs, sequences and progressions. Learning standard patterns is a fundamental element of mastering instrumental technique, exactly because they are so commonly used.
Melodic shapes, on the other hand, are fragments without a clear construction rule, generally specific to the piece in question. While longer melodic statements may include phrases that have been used in many other pieces, overall, the melody will be piece-specific.
In order to develop playing from memory, you should make a directed effort towards memorising your repertoire and playing it from memory. If thus far you have mostly been playing from sheet music, you should begin to incorporate pure memory playing into your practice. Thus, once you have memorised a piece (more on that in a second), you should try to henceforth play it from memory only, when practicing.
To develop a conscious memory of the piece, you'll need to analyse its construction in order to identify the standard patterns and melodic shapes that make it up. Don't try to take the whole piece in at once; rather, break down the form into its constituent sections and memorise one at a time.
To begin with, note the key, meter and tempo of the section you are studying. Next, look at the harmony and chord progressions - if your knowledge of harmonic theory is lacking, note and memorise the acutual chord names, if you're confident enough to identify the functional relationships, all the better - you can simply apply the memorised functional structure to the key you're playing in and not have to worry about naming each chord. Look at how the harmony is executed: whether it is through chord fragments, arpeggios, repeating patterns etc. and note how the chords change. You should be creating a mental map of the part, with any standard patterns serving as mental signposts.
When analysing the melody, be on the lookout for any runs, sequences, repeating patterns - anything that you can conveniently name and commit to memory. Again, the aim is to create mental shortcuts; rather than trying to memorise the melody note-by-note, standard patterns allow you to mark larger fragments with a name and starting note and can then be played from your knowledge of the pattern.
Melodic shapes that aren't standard patterns must be memorised note-by-note, but even here you should be looking for characteristic elements that can serve as mental signposts. Be especially aware of any phrase repetitions, directional changes and the like.
The key is to think as little in terms of individual notes to be played as possible. Every time you can "dump" a group of notes into a collective shape, pattern or progression you are saving mental overhead for memorising the rest of the piece. Naturally, your ability to do this will depend on your knowledge of standard patterns, so it's a good idea to devote some time to studying theory, harmony and fundamental techniques. This will further your understanding of what you are playing and thus make memorisation easier. You'll also probably find it easier to concentrate on one hand at a time so you are consciously aware of what each hand is supposed to be doing at any point.
Once you have the individual sections memorised, you'll need to bring them together by memorising the form of the piece. Again, you should be trying to think in terms of mental blocks (the sections you have studied) and be aware of any repetitions.
Thus far I've been focusing on the issue of notes (pitches) to be played, but the above also applies to rhythmic values - any time you can identify a repeating rhythmic shape, you can memorise it as a block, rather than thinking in terms of the individual values of each note and rest.