Complete Commentary on the Whole Bible, by Matthew Henry, at sacred-texts.com
(Psa 31:1-8) Confidence in God.
(Psa 31:9-18) Prayer in trouble.
(Psa 31:19-24) Praise for God's goodness.
Faith and prayer must go together, for the prayer of faith is the prevailing prayer. David gave up his soul in a special manner to God. And with the words, Psa 31:5, our Lord Jesus yielded up his last breath on the cross, and made his soul a free-will offering for sin, laying down his life as a ransom. But David is here as a man in distress and trouble. And his great care is about his soul, his spirit, his better part. Many think that while perplexed about their worldly affairs, and their cares multiply, they may be excused if they neglect their souls; but we are the more concerned to look to our souls, that, though the outward man perish, the inward man may suffer no damage. The redemption of the soul is so precious, that it must have ceased for ever, if Christ had not undertaken it. Having relied on God's mercy, he will be glad and rejoice in it. God looks upon our souls, when we are in trouble, to see whether they are humbled for sin, and made better by the affliction. Every believer will meet with such dangers and deliverances, until he is delivered from death, his last enemy.
David's troubles made him a man of sorrows. Herein he was a type of Christ, who was acquainted with grief. David acknowledged that his afflictions were merited by his own sins, but Christ suffered for ours. David's friends durst not give him any assistance. Let us not think it strange if thus deserted, but make sure of a Friend in heaven who will not fail. God will be sure to order and dispose all for the best, to all those who commit their spirits also into his hand. The time of life is in God's hands, to lengthen or shorten, make bitter or sweet, according to the counsel of his will. The way of man is not in himself, nor in our friend's hands, nor in our enemies' hands, but in God's. In this faith and confidence he prays that the Lord would save him for his mercies's sake, and not for any merit of his own. He prophesies the silencing of those that reproach and speak evil of the people of God. There is a day coming, when the Lord will execute judgment upon them. In the mean time, we should engage ourselves by well-doing, if possible, to silence the ignorance of foolish men.
Instead of yielding to impatience or despondency under our troubles, we should turn our thoughts to the goodness of the Lord towards those who fear and trust in Him. All comes to sinners through the wondrous gift of the only-begotten Son of God, to be the atonement for their sins. Let not any yield to unbelief, or think, under discouraging circumstances, that they are cut off from before the eyes of the Lord, and left to the pride of men. Lord, pardon our complaints and fears; increase our faith, patience, love, and gratitude; teach us to rejoice in tribulation and in hope. The deliverance of Christ, with the destruction of his enemies, ought to strengthen and comfort the hearts of believers under all their afflictions here below, that having suffered courageously with their Master, they may triumphantly enter into his joy and glory.