Then when he says, But when we, he presents the cause on God's part, saying: But when we are judged by the Lord, i.e., punished in this world, we are chastened, i.e., this is done for our correction, in order, namely, that each one withdraw from sin on account of the punishment he endured: "Happy is the man whom God reproves" (Jb 5:17); "Whom the Lord loves he chastises" (Pr 3:12), or even when through the punishment of one, another ceases to sin: "Strike a scoffer and the simple will learn prudence" (Pr 19:25) and this in order that we may not be condemned with eternal damnation in the future..., along with the world, i.e., with worldly men.
Source: Commentary on 1 Corinthians