Throughout my mathematical career, I've been deeply humbled by math many times. I, like many others who choose to study math, was naturally "good" at the subject growing up, but this ended very abruptly when I started taking proof based courses. It wasn't only the material that was difficult — I felt like I was having an identity crisis! Wasn't I supposed to be the person that understood math easily and quickly? What was I without that?
I think most of us who make it to graduate school in mathematics have to wrestle with these questions. And to be clear, it's really hard! It's hard to suddenly struggle with your best subject and watch others around you grasp it with ease. It can make you question your own abilities to study mathematics. I certainly did. I was worried I would never understand the material and my career as a mathematician would end before it began.
It is because of these fears that I decided to include this page on my website. Both at the beginning of my undergrad and at the beginning of my Ph.D., I worried immensely about my perceived lack of mathematical ability. I needed to be told these things by someone was further along in their mathematical career and had been in my shoes.
Mathematical intuition takes time. It is normal to at first feel like results in your courses came out of nowhere; with time, you pick up the context surrounding them. It is with repeated exposure to the material that working with the concepts becomes like second nature. By repeated exposure, I mean months to years! Give it time. Let it marinate in your brain.
Because the intuition takes time to build, spending a lot of time on problem sets is normal. You aren't dumb and you aren't doing anything wrong. Give yourself plenty of time to work on them.
But also, sometimes the most productive thing you can do is step away from your work. Spending hours making no progress is akin to running on a treadmill: you're getting nowhere, and you're wearing yourself out in the process. Of course, there is very real worth in getting stuck for awhile, but know when enough is enough. Consider switching to working on something else, or, even better, go talk to other people, be it professors, classmates, your friends, etc. They can offer a new perspective that gets you unstuck, or point out something you're missing. Considering that math research is a collaborative process, this is legitimately preparing you for research.
And even if you can't understand the material in a course, getting a bad grade seems a lot scarier than it actually is. I've been there! With practice, I've managed to shift my perspective from "I can't understand this math and I never will", to "I just need to let this math marinate in my brain for longer", which not only feels better, but is more accurate of the situation.
I want to end by validating that math is hard. If it were easy, there wouldn't be anything to study! If you feel frustrated, dumb, stuck, slow, etc. at times (or even often), you're in good company. If you feel that math is a worthwhile endeavor for you, then math is for you. I like to say that in order to study math, talent helps, but all you actually need is to be very, very stubborn.
I wish you the best!