Psalm 51:1-2 is one of the cries of David's heart after he had committed sin. He knew that only God's mercy could help him. In Romans 4, we see the answer. David's prayer has been answered for us as well in Jesus Christ.