He rebuked Job and insisted that the righteous are not cut off. I believe a key verse in these chapters is verse 17 of chapter 5. God is just, and must correct His children. When we are chastised it is for our own good. God loves us, and chastens us because He loves us.
Parents correct their children when they have been disobedient.
Sometimes a rod is necessary. But we do not correct our children because we are brutal or unloving, but because we do love them and want to teach them the way they should go. So it is with God. When His children falter, and fail to repent of their sin, He must chastise them in order to bring them back to Himself.