5 “Gracious is the Lord, and righteous; yea, our God is merciful”. He is gracious, righteous, and merciful. Gracious in the first place, because He has inclined His ear unto me; and I knew not that the ear of God had approached my lips, till I was aroused by those beautiful feet, that I might call upon the Lord's Name: for who has called upon Him, save he whom He first called? Hence therefore He is in the first place “gracious;” but “righteous,” because He scourges; and again, “merciful,” because He receives; for “He scourges every son whom He receives;” nor ought it to be so bitter to me that He scourges, as sweet that He receives. For how should not “The Lord, who keeps little ones”, scourge those whom, when of mature age, He seeks to be heirs; “for what son is he whom the father chastens not?” “I was in misery, and He helped me.” He helped me, because I was in misery; for the pain which the physician causes by his knife is not penal, but salutary.
Source: The Enarrations, or Expositions, on the Psalms (New Advent)