Why do the righteous suffer? John Piper writes about this passage: “Elihu puts the pain of sickness and visions of the night side by side as two ways that God speaks to man for his good. Verse 17 describes God’s purpose: ‘That he may turn man aside from his deed, and cut off pride from man, and keep back his soul from the Pit.’ In other words God’s purpose for the righteous in these dreams and in this sickness is not to punish but to save—to save from contemplated evil deeds and from pride and ultimately from death. Elihu does not picture God as an angry judge but as a Redeemer, a Savior, a Rescuer, a Doctor. The pain he causes is like the surgeon’s knife, not like the executioner’s whip” (John Piper, “Job: Rebuked in Suffering” [sermon, July 21, 1985], Desiring God, https://www.desiringgod.org/messages/job-rebuked-in-suffering).