Certain provinces practice this ritual as a sort of sacrifice. Some rural areas are very old fashioned and steeped in tradition and they believe that by beating themselves during Holy Week, they are offering their personal comfort as either a sacrifice for a favor that they are asking in prayer or as thanksgiving for a prayer answered.
Usually, they will make a commitment thru prayer that they will do this annually if God answered their prayers (often, of a serious nature, like a loved one being cured of a deadly disease or something like that).