Note: We cannot diagnose a medical condition nor give you medical advice, so this answer addresses the generalities of a baby raising their head; in your specific instance, if you have any medical concerns, please call your pediatrician.
One of the earlier milestones you will track is neck/head control, and it sounds like you're in the middle of that right now. At around the age you're describing (often as early as 3 months), babies start to be able to raise their head to 90 degrees, and will often do that repeatedly as they build neck muscles.
The Bump recommends a very similar exercise with them a bit earlier in development (around 3 months):
Lay baby on his or her back and gently pull baby up by the hands, hold for a second or two and lower baby to the ground. It’s normal for there to be some “lag” in baby’s head at this age, so go slowly. These baby “sit-ups” are an excellent way to build baby’s neck muscles.
It sounds like your baby is able to do that by themselves, which is great - even stronger neck muscles ahead! It also sounds like they are perhaps ready for more tummy time - that's the best place to practice neck muscle exercises as it's a lot more interesting than on their back! They may be trying to turn over, and just not quite yet figuring out how. Consider turning them over when they start doing this, if you're able to have some supervised tummy time then, as it may be what they're after anyway!
This typically transitions into sitting and crawling (sometimes together, sometimes separately).
If you're specifically concerned about the force the baby is hitting the mat with, please check with your pediatrician; that's why they're there. It's a bit harder to tell with infants when a serious head injury has occurred, as many of the symptoms of a serious head injury rely on things like talking or walking that an infant can't do (or can't tell you about, such as blurred vision), but you can certainly pay attention for any changes in your child's behaviors. Please call your pediatrician if you have any concerns in this area.