The Flagellant movement did not arise until the 1200s, but there were always elements in the early Church. Some of the practices came from the OT extravagance of penance such as:
Ezra 9:[3] When I heard this, I rent my garments and my mantle, and pulled hair from my head and beard, and sat appalled. [4] Then all who trembled at the words of the God of Israel, because of the faithlessness of the returned exiles, gathered round me while I sat appalled until the evening sacrifice. [5] And at the evening sacrifice I rose from my fasting, with my garments and my mantle rent, and fell upon my knees and spread out my hands to the LORD my God, [6] saying: "O my God, I am ashamed and blush to lift my face to thee, my God, for our iniquities have risen higher than our heads, and our guilt has mounted up to the heavens. [7] From the days of our fathers to this day we have been in great guilt; and for our iniquities we, our kings, and our priests have been given into the hand of the kings of the lands, to the sword, to captivity, to plundering, and to utter shame, as at this day.
Jeremiah 41:5 eighty men arrived from Shechem and Shiloh and Sama'ria, with their beards shaved and their clothes torn, and their bodies gashed, bringing cereal offerings and incense to present at the temple of the LORD.
1 Corinthians 9:27 but I pommel my body and subdue it, lest after preaching to others I myself should be disqualified.
[cf. NIV, Beck: "beat"; NEB: "bruise"; Williams: "beating and bruising"; Barclay: "batter"; NASB: "buffet"; NRSV: "punish"; NKJV: "discipline"; Wuest: "I beat my body black and blue and make it my abject slave"; Amplified: "I buffet my body -- handle it roughly, discipline it by hardships -- and subdue it"; Goodspeed: "I beat and bruise my body and make it my slave"; Moffatt: "I maul and master my body"
from http://socrates58.blogspot.com/2010/02/biblical-evidence-for-penitential.html
Now, it is not and never has been the doctrine of the Church that one must inflict deliberate injuries, but rather in the manner of fasting and penitance that one should act.
The problem is the church keeps making saints of people that did it