David wrote Psalm 51 after being confronted by the prophet Nathan about the sins he had committed, more particularly the adultery with Bathsheba and the subsequent murder of Uriah, Bathsheba's husband, in an attempt to hide Bathsheba's pregnancy that resulted from the adultery. This psalm is a model for true repentance which is consists of "conviction, confession, sorrow, prayer for mercy, and purposes of amendment, and it is accompanied by a lively faith". (Jamieson, Faussett and Brown Commentary)
When David realized the depth and depravity of his sins, he became spiritual broken, and David turned to God, the only One who could restore him. "When we deal seriously with our sin, God will deal gently with us. When we hate what the Lord hates, he will soon make an end of it, to our joy and peace." (Treasury of David by Charles Spurgeon)
David asked God to "wash away my guilt, and cleanse me from my sin" (verse 2). He desired forgiveness and to be made pure. The guilt that David was experiencing was righteous because the source of the guilt was unconfessed sin in his life. After God forgives a sin there is no need to feel guilty anymore; God no longer remembers the sin. Guilt over a forgiven sin is a tactic used by Satan to make us ineffective witnesses for God.
In verse 3 David acknowledged his sin and is willing to take responsibility for it. "Conviction precedes forgiveness." (Jamieson, Faussett and Brown Commentary)
David recognized that even though many were affected by his sins, ultimately his sins were against God (verse 4). He knew that God had seen his sins and that his attempts to hide them were futile. Also, David knew that only God could render judgment against him. David had no defense for his sins so he did not waste his time making excuses, but instead pled for mercy. David knew that whatever judgment God decided upon, it would be true and just.
Nathan's rebuke to David was God's way of shining a light into David's soul and revealing to David all of his sins, including the ones he overlooked, excused, diminished and tried to conceal. As a result of his spiritual brokenness, David was bearing his soul to God, and in verse 5 David acknowledged that by nature he is a sinful person. He was no longer trying to hide his sins from God.
David knew that what God desires is integrity (verse 6). Integrity is when your actions match your beliefs. For a Christian this means our actions should reflect the new spirit we received when we were born again. This is important because God is interested in both what we do and why we do it. He does not want us to do things just for show.
Integrity is lacking in our lives when we sin and act like those who are lost. Faithfulness to God will result in a life full of integrity. Without wisdom from God a life filled with integrity is impossible for it is wisdom from God that teaches us what is right and wrong. "The penitent feels that God is teaching him truth concerning his nature, which he had not before perceived." (Treasury of David by Charles Spurgeon)
David had faith that God could cleanse him from his sins and make him spiritually clean (verse 7) and then his relationship with God would be restored as well as his joy and gladness (verse 8). David asked that his sins be hidden from God (verse 9). "God's forgiveness involves the removal of sin's power from our lives and not just the feelings of guilt about having sinned." (Explore the Bible - Adult Learner Guide, Fall 2009, p. 55)
In verse 10 David requested a miracle from God -- to create within him a clean heart. This is a request for a miracle because only God can create anything new. David acknowledged that he could not be the man that God desired him to be with the heart he had.
David also knew his spirit was not what it needed to be so he asked for a "renewed steadfast spirit". The Hebrew word for renew is châdash which means to be new, to rebuild or repair. Adam Clarke's Commentary describes a "right spirit" as a "constant, steady, determined spirit" and "no longer bound and degraded by the sinfulness of sin". "Right conduct can come only from a clean heart and spirit" (Life Application Bible Notes); and it is the way to integrity.
David asked God to neither cast him away nor take the Holy Spirit away from him (verse 11). David was aware that this had happened to Saul, and he did not want to suffer the same fate. However, the fact that David was convicted of his sins is proof that the Holy Spirit had not departed from him. David wanted his relationship with God restored. Sin damages our fellowship with God and adversely affects our usefulness and effectiveness in our ministry.
David had lost his joy because of his sins, and he wanted it back along with a willing spirit to obey and serve God (verse 12). David wanted opportunities to teach others who rebel against God so that they may also repent of their sins (verse 13). "When God forgives our sin and restores us to a relationship with him, we want to reach out to others who need this forgiveness and reconciliation. The more you have felt God's forgiveness, the more you will desire to tell others about it." (Life Application Bible Notes)
Not once in this psalm does David request that God remove the consequences of his sins. He was willing to endure the consequences, but he could not bear being separated from God. His sin had caused a break in his fellowship with God, and David wanted that fellowship to be restored. Only then would he once again be joyful. Following David's example we too can have our relationship with God restored after we have sinned as well as our joy and our witness for God.