If you've ever played an instrument, you know that after enough practice, your body can start to take over. Unlike when you first started playing a song, you no longer have to think about each and every note that you're playing. This is when your muscle memory steps in.
Whenever I practiced, I would play the same couple of measures until I knew them and then would slowly piece them all together. By playing each segmented piece of the song over and over again I was building my muscle memory, which changes the "way your brain reacts to these movements, resulting in quicker, repeated motions," as explained in the article "Learning to Play Music: The Phenomenon of Muscle Memory."
Although, when explaining what exactly muscle memory is, you should also know that there are two types of memory: discursive and procedural. While your discursive memory is the ability to remember facts, your procedural memory is where your muscle memory takes place. According to the article "What is 'Muscle Memory," your procedural memory is about the ability to do things without "analytically recalling facts about what to do," and it takes two steps to put a sequence of notes into your procedural memory. These steps come from Fitts' theory, starting with the cognitive phase "where you have to consciously think about everything" and ending with the autonomous phase, when "the action can be carried out more or less unconsciously."
In the end, building muscle memory is all about forcing these rhythms into your memory by practicing the same couple of measures over and over again. Although in order for this method to be useful you need to be certain that each time you repeat a section you are playing it correctly and don't start to slack off towards the end. If you build muscle memory while holding your instrument the wrong way or play the notes or rhythms wrong you will end up doing more harm than good. As long as you keep practicing correctly you will have successfully built your muscle memory and can go on to worry about musicality.