22 “And the Lord has become my refuge”, he says. You would not seek such a refuge, if you were not in danger: but you have therefore been in danger, that you might seek for it: for He teaches us by sorrow. He causes me tribulation from the malice of the wicked: pricked with that tribulation, I begin to seek a refuge which I had ceased to seek for in that worldly prosperity. For who, that is always prosperous, and rejoices in present hopes, finds it easy to remember God?
Let the hope of this life give way, and the hope of God advance; that you may say, “And the Lord has become my refuge:” may I sorrow for this end that the Lord may become my refuge! “And my God the help of my hope.” For as yet the Lord is our hope, since as long as we are here, we are in hope, and not in possession. But lest we fail in hope, there is near us a provision to encourage us, and to mitigate those very evils which we suffer. For it is not said in vain, “God is faithful, who will not suffer you to be tempted above that you are able: but will with the temptation also make a way to escape, that you may be able to bear it:” who will so put us into that furnace of tribulation, that the vessel may be hardened, but not broken.
“And the Lord has become my refuge: and my God the help of my hope.” Why then did He seem to you to be as it were unjust, in that He spares the evil? See then how the Psalm is now set right, and be thou set right together with the Psalm: for, for this reason the Psalm contained your words. What words? “Lord, how long shall the ungodly, how long shall the ungodly triumph?” The Psalm just now used your words: use therefore yourself the Psalm's words in your turn.
Source: The Enarrations, or Expositions, on the Psalms (New Advent)