According to its title, David wrote Psalm 51 in response to his sin with Bathsheba and the word of judgment that God sent to him through Nathan the prophet. David had indeed sinned grievously, not only by committing adultery with Bathsheba, but also by arranging the murder of her husband, Uriah, to cover up his sin.
Metrical Verses 1-4 (Book of Praise of the Canadian Reformed Churches © Copyright 2014)