Self-flagellation is form of mortification of the flesh.
"For if ye live after the flesh, ye shall die: but if ye through the Spirit do mortify the deeds of the body, ye shall live."
"Mortify therefore your members which are upon the earth; fornication, uncleanness, inordinate affection, evil concupiscence, and covetousness, which is idolatry."
"And those who belong to Christ Jesus have crucified the flesh with its passions and desires."
"Blows that wound cleanse away evil; beatings make clean the innermost parts."
It was practices and is practices by many, of which many also became saints. Even Martin Luther practiced it (even though he hated "monky" things). Even one of his infamous thesies are "inner repentance is worthless unless it produces various outward mortification of the flesh."
But one must remebrs, that it is means, not ends. There have to be humility and prudence in mortification. And if you want to do severe stuf, like self-flagellation, you have to do it under gudiance of spiritual director.
Doing it for plesure is sin (but enoying it for the sake of Christ, spirutally, is not, as Paul writtes "I rejoice in my sufferings for your sake").
Likewise, if you do it for reasons of scrupulosity you are sick man.
And of course, Flagellantism as it was practiced by heretics in 14th century is to be avoided peroid.