P.M.
My grandson would hit himself when angry or frustrated at around that age. My take was that he was not allowed to hit or hurt other people, and he was the least powerful person in any exchange, so when he felt a strong urge to strike out, he was his own target. This was most likely to happen when he was being reprimanded or corrected, which seemed to increase his sense that he should be punished.
We showed him how to express anger physically on an inanimate object, like pounding on a pillow. We gave him words to use, "I feel mad (or sad)." We gave him very clear permission to express himself in those ways. And then we pretty much ignored the times he hit himself. Within a couple of weeks, he was no longer doing that.