What causes an inability to recall a melody, beat, or music?
The following answer is based on my own experience learning music combined with general principles of cognitive psychology related to skill acquisition.

I think that learning music would help a person recall a melody, a beat, and music in general. Formal training would be particularly helpful, but informal training would also often have a similar result.

In particular, learning music teaches you how music is structured. This training teaches you a whole range of skills. You learn to isolate instruments. You learn about the structure of songs (e.g., bars, beats, sections, repetition). You learn about melody (e.g., scales, intervals, chords, progressions, etc.). You learn about rhythm. 
There is a theoretical aspect to this knowledge whereby you conceptually understand the ideas. However, there is also a large procedural component whereby you train your ear to identify different sequences, and you also learn to produce such sequences with a suitable instrument.

Learning to sing can be particularly helpful in training your ability to reproduce melody without the song present. Singing trains you to be able to reproduce intervals, scales, and so on without an external source.

All this declarative and procedural knowledge of music simplifies and enables the mental recall of music. For example, instead of seeing a pop-song as a 3 minute stream of sound, You start to see the simplicity of for example, 3 chords, and 2 major melodic elements. You see the similarities with other songs in terms of the chord progressions, scales, and rhythm. It's similar to the way that language becomes simpler once you appreciate the basic principles of vocabulary and grammar.

Beyond musical skill, actual repetition and spending time seriously thinking about the song should also help in the recall a that specific song.