God is treating you as one of His children. You have a Father in heaven who loves you enough to discipline you. It is for your blessing, that you would share in God's holiness and produce the fruits of righteousness and peace. God is training us, the way a coach trains and disciplines the athletes under his care. A coach stretches and pushes and exercises his athletes, so that they run their race with endurance.
Training is no fun at the time.
No one likes it. Training is often painful and unpleasant. He's training us for righteousness, disciplining us to run the race set before us, stretching and strengthening our faith in Christ. Sometimes God disciplines us because of our sin. He disciplined Israel who disobeyed Him in the wilderness and let a whole generation die without seeing the promised land.