God chastens us as a loving parent trains and teaches a child, sometimes for correction and sometimes for prevention. It is not punishment; it is something He has to do for our benefit to conform us to the image and likeness of Christ so that we may be partakers of His holiness in eternity. There is no pleasure in chastisement, but He does it out of love and we will come through it transformed and be displayed as His treasures in eternity.