Self-flagellation is the act of beating oneself with things such as whips, lashes, rods, chains, knives, etc. willingly, especially in religious context.
In early times, among certain Catholic sects, self-flagellation was apparently imposed as punishment and as a means of penance for disobedient clergy. It was a widespread practice during the Holy Week in Mediterranean countries as a reminder that Jesus Christ was whipped before the Crucifixion. It was also promoted as a means of identification with the suffering of Christ. Pope John Paul II regularly whipped himself as a sign of “remorse for his sins” and to bring himself closer to Christ.
But Catholics are not alone in adhering to self-flagellation. Many Muslims, especially from South Asia, also practice Matam during Muharram. In this, they lash themselves until they bleed.
Self-Flagellation and Self-Harm is Not Allowed in Islam
Self flagellation, a form of self-harm, is the worst way of expressing and dealing with deep distress and emotional pain. It may include beating oneself, putting oneself in risky situations, or not looking after one’s own physical or emotional needs. In Islam, it is not permissible to harm oneself or throw oneself into destruction by any means. Allah says in the Quran: 
Let not your own hands contribute to your destruction.
It is also disallowed to expose oneself to the risk of illness or injury in any manner, or to kill oneself in extreme situations. Allah says: 
In Islam, there is no room for actions of self-flagellation such as beating chests, slapping cheeks, striking shoulders with chains and cutting the skin with blades. These barbaric acts are innovations and acts of ignorance.
And do not kill yourselves.
Self-Flagellation is Prohibited in Hadith Too
Prophet Muhammad (PBUH) too disliked such evils and forbade them. Any of these acts of self-harm (or anything similar to them) to mark the death of a leader or the loss of a martyr, no matter what his status be, is prohibited. Such actions have no basis in Islam. Narrated Abdullah that Prophet Muhammad (PBUH) said: 
He who slaps his cheeks, tears his clothes and follows the ways and traditions of the Days of Ignorance is not one of us.
As Muslims, we are required to take charge of our lives since we are accountable for our deeds and decisions, both for ourselves and for others who will be affected. We are not allowed to harm ourselves. Instead, we are taught dignity, self-respect and righteousness. Narrated Abu Juhaifa that Prophet Muhammad (PBUH) said: 
Your Lord has a right on you and your soul has a right on you; so you should give the rights of all those who has a right on you.
To feel pain and shed tears in grief and distress is something no one can be blamed for. What is forbidden is that many people turn towards inflicting harm on themselves as an expression of grief.
Islam aims to create balance in our lives. Islam has given us the necessary directives to handle and overcome stressful situations. It is very unfortunate that in spite of clear Guidance from Allah in The Quran, many Muslims practise self-flagellation and self-harm. During Muharram, primarily on the Day of Ashura, certain Muslims whip themselves. They go as far as hitting themselves with swords and chains.
Why? To commemorate the martyrdom of Hz Ḥussain (RA). As is obvious from the above references, self-flagellation is not a permitted manner of expressing one’s grief.
Lastly, in the Quran, Allah has declared four months as sacred, and the month of Muharram is one of them: 
Indeed, the number of months with Allah is twelve months in the Sight of Allah (from) the day He created the heavens and the earth; of these, four are sacred. That is the right reckoning, so do not wrong yourselves during them.
What we are supposed to do in these sacred months? Obviously, we should not “wrong” ourselves. We should avoid unlawful deeds like self-flagellation and instead focus on piety and righteousness as much as we can.
- The Quran 02:195 (Surah al-Baqarah)
- The Quran 04:29 (Surah an-Nisa)
- Sahih Bukhari Vol 02, Book 23, Hadith 382
- Sahih Bukhari Vol 03, Book 31, Hadith 189
- The Quran 09:36 (Surah at-Tawbah)