Thank you for asking a question on thisisyourbible.com
There are only two places where this phrase occurs in reference to David.
This is how the KJV presents these verses:
1 Samuel 24:5 And it came to pass afterward, that David's heart smote him, because he had cut off Saul's skirt.
2 Samuel 24:10 And David's heart smote him after that he had numbered the people. And David said unto the LORD, I have sinned greatly in that I have done: and now, I beseech thee, O LORD, take away the iniquity of thy servant; for I have done very foolishly.
Here is how the New Living Translation presents these same verses:
1 Samuel 24:5 But then David's conscience began bothering him because he had cut Saul's robe.
2 Samuel 24:10 But after he had taken the census, David's conscience began to bother him. And he said to the LORD, "I have sinned greatly by taking this census. Please forgive my guilt, LORD, for doing this foolish thing."
It means that David felt guilty about what he had done. In the first case, he had disrespected "the Lord's anointed" even though Saul was his enemy and was seeking to kill him. In the second case he had violated the law of God in the way in which he had numbered the people. In both cases, his conscience bothered him because he felt he had done wrong.
I hope you have found this helpful.
May God bless you,