This question is obviously old, but it might have general relevance, so want to give at least a few pointers.
There are physical conditions related to the perception of pain that could encourage such behavior, but the age of the boy and the setting you described doesn't currently speak in favor of these.
On a more psychological level the boy's behavior reminds me of https://en.wikipedia.org/wiki/Self-harm although such behavior is usually observed in people who are older than 3.5 years.
According to my experience emotional pain that has become unbearable by the one experiencing it turns into physical pain. This is a powerful subconscious process which can lead to all sorts of physical pain, including diseases, but one possible expression of it is indeed self-harm.
It cannot be controlled consciously, at least not directly.
I have every reason to assume that this process can also take place in a 3.5-year-old.
From your description it sounds plausible that the child was experiencing extreme emotional pain prior to his self-injuries. What is not totally clear is the nature and cause of this pain. The punishment itself may have contributed, but unless it was really extreme, violent, and unsympathetic I would assume that the boy's misbehavior was already an expression of emotional pain that was then aggravated by the punishment.
If that theory is true, he needs help to explore his pain so he can solve it. At his very young age competent adult reference persons will have to play an important role in this process, so adults around him must be willing to observe and listen. His behavior shouldn't be primarily seen as disturbing and in need of punishment but rather as a starting point for the exploring what's wrong.
The emotional pain behind his behavior may originate from a time where he did not have words or any kind structured thinking yet, that's why it shouldn't be assumed that he can verbally describe what's going on in his soul when he feels like this.
Another idea I'm getting is that the boy maybe has a long history of conditioning which ultimately lead to such extreme behavior. Sometimes adults see a kid as primarily disturbing, and they unwillingly encourage disturbing behavior in the course: If the kid is quiet, they leave him/her alone. Then the kid is lonely, bored, neglected, and not happy. If however he creates a lot of fuss, he suddenly has everyone's attention. Humans find negative attention better than no attention at all, so even if the kid is punished as a result of his behavior, he will experience this as a positive consequence if the alternative is not to receive any attention at all (if he's behaving well), effectively rendering the punishment counterproductive.
This thing can go on over years in a kind of vicous circle where adults are increasingly helpless and increasingly longing for just some peace, so they become ever more willing to ignore the kid. Which in turn makes it necessary for the child to show ever more extreme behaviors to keep receiving attention.
What speaks in favor of this theory in this particular case is that the punishment sounds like it could've been meant to make the boy less disturbing thereby possibly being an example for an ongoing pattern in the family/social environment.
Both conditions/ideas that I mentioned are hard to solve without someone from outside the family system of the kid, ideally a professional.
If you want to solve it alone once it has already entered such an extreme stage, you need a strong ability to look at yourself and others from a neutral point of view and to reflect everyone's behavior from that perspective. It's usually not easy to see behind subconscious and automatic behavior patterns without the help of someone who isn't affected. If the problem persists and the questioner is still reading, I recommend seeking some kind of professional advice from someone who can directly observe everyone involved if indicated after hearing the issue more in detail.