David wrote Psalm 51 after his sin with Bathsheba. That sin might now have occurred if he had been doing what kings were supposed to do. 2 Samuel 11:1 says, “It happened…at the time when kings go out to battle…But David remained at Jerusalem.” In his boredom, he did not guard his heart.
Psalm 51:4 says, “Against You, You only, have I sinned, and done this evil in Your sight—that You may be found just when You speak, and blameless when You judge.” Our disobedience is sin against the One who gave His life for us ~ out of love.
Our heart’s maintenance is to guard it from our fleshly suggestions, clinging instead to the truth of God’s word, and applying it daily to our lives. His prayer in verse 10 is one we can adopt. It says, “Create in me a clean heart, O God, and renew a steadfast spirit in me.”