God, You, and Discipline

Discipline does not feel good at it. Especially, when you feel like you’re being unfairly punished. Why does God use punishment as a tool? How useful is it?