Supposedly punitive self-flagellation trains you not to make the same mistakes. However, the cycles of rumination embed negativity, leading to repetition and catastrophizing.
Equally, these behaviors happen internally, pulling you out of the present reality to focus attention inward.
Attention is a precious light: by focusing you prioritize. By beating yourself up you miss out on the world, the only place you can find redemption.