Like a father, God disciplines His children when they are rebellious. When we do not obey, He will discipline us and give us opportunities to change ourselves—showing His mercy to us.
And you have forgotten the exhortation which speaks to you as to sons: "My son, do not despise the chastening of the LORD, Nor be discouraged when you are rebuked by Him ~ Hebrews 12:5