Psalm 51 is one of the most popular Psalms of confession and repentance. The introduction to the Psalm tells the reader of the occasion: “To the choirmaster. A Psalm of David, when Nathan the prophet went to him after he had gone into Bathsheeba.” The context of the Psalm is 2 Samuel 11-12. King David, while neglecting his kingly duties, committed adultery and had Bathsheba’s Husband Uriah killed in an attempt to cover up his sin. After being confronted David is moved to true repentance and writes Psalm 51.
The focus on the presence of God is found in verse 9-11:
 Hide your face from my sins, and blot out all my iniquities.  Create in me a clean heart, O God, and renew a right spirit within me.  Cast me not away from your presence, and take not your Holy Spirit from me.  Restore to me the joy of your salvation, and uphold me with a willing spirit.
David’s request in verse 9 is that God would hide his face (paniym פָּנִים). Charles Spurgeon comments on this verse saying that David is asking that God “not look at them; be at pains not to see them. They thrust themselves in the way; but, Lord, refuse to behold them, lest if thou consider them, thine anger burn, and I die.” This may seem contradictory to his later request in verse 11 to “cast me not away from your presence (paniym פָּנִים).” But the context makes it clear that David’s request in verse 9 is that God would not look upon his sin, but instead blot it out.
This is a request for God’s grace and forgiveness. Verses 10 and 11 contain requests for God’s blessing through his presence; that this not be removed, and for a renewed inner man that is washed clean of sin. There has been much debate around this passage. Does it teach that the indwelling Holy Spirit can be removed and salvation is taken away? John Calvin reassures that it does not:
The truth on which we are now insisting is an important one, as many learned men have been inconsiderately drawn into the opinion that the elect, by falling into mortal sin, may lose the Spirit altogether, and be alienated from God. The contrary is clearly declared by Peter, who tells us that the word by which we are born again is an incorruptible seed, (1 Peter 1:23;) and John is equally explicit in informing us that the elect are preserved from falling away altogether, (1 John 3:9). However much they may appear for a time to have been cast off by God, it is afterwards seen that grace must have been alive in their breast, even during that interval when it seemed to be extinct. Nor is there any force in the objection that David speaks as if he feared that he might be deprived of the Spirit.
It is natural that the saints, when they have fallen into sin, and have thus done what they could to expel the grace of God, should feel an anxiety upon this point; but it is their duty to hold fast the truth that grace is the incorruptible seed of God, which never can perish in any heart where it has been deposited. This is the spirit displayed by David. Reflecting upon his offense, he is agitated with fears, and yet rests in the persuasion that, being a child of God, he would not be deprived of what indeed he had justly forfeited.
Psalm 51 teaches of the seriousness of sin, the necessity of repentance, and the need of God’s gracious presence. The restoration of David, or any sinner, would not be possible if God did not, in His infinite grace and mercy, hide his face from sin, blot them out, and restore sinners to his presence. Thanks be to God who, in Christ, restores sinners like us to his presence.