I tried to just bang it out and keep playing over and over to get the muscle memory but it feels like its not coming along and its just hurting my hand to spam it out. I've only been playing for 5 min but still. Is it just a matter of time? Should I perhaps play it multiple times per day instead of one 20-30 min session spent on learning?
Practice it by playing it as slowly as needed to attain as close to 100% accuracy as possible (no perceivable mistakes). Use a metronome. Once you master it at a given slower tempo, speed it up until it becomes a challenge again and practice at the faster tempo until you master it at that tempo.
Repeat this process until you can actually achieve 100% accuracy at a slightly faster than normal tempo, then you will have it down.
If you practice at a tempo where you are consistently making mistakes, you will not be developing the correct muscle memory. Instead you will be ingraining your tendency to make mistakes.
Be patient. Some passages or pieces are more difficult and take time to master.
Think more about what can happen over the course of days rather than one day. Work on something else musical or (perhaps better) go do something completely different like go for a jog or a walk.
Something happens when you work hard on something, then go away from it (or sleep) and come back to it. (Maybe work on it a bit before you go to bed, then again in the morning.) Whatever you do don't force it. You can only learn at your own pace.
If you're otherwise having difficulty with the figure, try breaking it into smaller pieces and getting the portions right before putting them together. You may be trying to get to performance level before you're ready. You don't want that "forcing it and my hand hurts" quality to be in the playing, whatever the style is.
IMO the best way to learn a repetitive part is to play it every day, starting from low bpm. When you feel comfortable then increment the bpm. But, after all, it's only a matter of time, and patience.
You're going to need mnemonics. You need to have a mental picture of some sort that you can hang the notes on. It could be a story, it could be some symbols representing formal structure -- etc.
I read somewhere that one needs to put something into short-term memory repeatedly so that the item can be recalled comfortably, at the person's speed.
The point of the slow practice is to eliminate tension while you build fluency.
I'll address the issue of pain from a repetitive piece since the other answers didn't, although I agree with them about slowing down to gain accuracy. You have muscles in your fingers and arms that need strengthening just like for any physical activity. Pain is your body's way of telling you to back off a bit.
It helps to go back to basics. Make sure you have a bench at the proper height, that you aren't bending your wrists, and you're holding your fingers loosely cupped, not tightly flexed or cramped. Pay extra close attention to getting the fingering right. If it's not written for you, write it down yourself with a pencil in key places.
When you feel pain, stop. Stretch your fingers gently. Wait until the pain subsides, plus a little longer, then try again. As you build up your muscles, and build up your speed, and focus on proper positioning and fingering, you'll see your endurance increase. People in good shape can play all day, with short breaks, but it took them a while to get to that point.