One of the penitential psalms, Psalm 51 was written by David after he was confronted by the prophet Nathan. Nathan declared that David had grievously sinned against God in the taking of Bathsheba to be his wife and in the murder of her husband, Uriah.
It’s important to see the anguish and heartfelt remorse expressed by David, but we must also understand that repentance of the heart is the work of God the Holy Spirit. David is repentant because of the influence of the Holy Spirit upon him. Not only that, but as he writes this prayer, he is writing it under the inspiration of the Holy Spirit. The Holy Spirit demonstrates in Psalm 51 how He produces repentance in our hearts. Keep this in mind as we look at the psalm.