After Saul returned from fighting the Philistines, he was told that David had gone into the wilderness of En-gedi.
References for 1 Samuel 24:1
So Saul chose 3,000 elite troops from all Israel and went to search for David and his men near the rocks of the wild goats.
At the place where the road passes some sheepfolds, Saul went into a cave to relieve himself. But as it happened, David and his men were hiding farther back in that very cave!
“Now’s your opportunity!” David’s men whispered to him. “Today the LORD is telling you, ‘I will certainly put your enemy into your power, to do with as you wish.’” So David crept forward and cut off a piece of the hem of Saul’s robe.
But then David’s conscience began bothering him because he had cut Saul’s robe.
He said to his men, “The LORD forbid that I should do this to my lord the king. I shouldn’t attack the LORD ’s anointed one, for the LORD himself has chosen him.”
So David restrained his men and did not let them kill Saul. After Saul had left the cave and gone on his way,
David came out and shouted after him, “My lord the king!” And when Saul looked around, David bowed low before him.
Then he shouted to Saul, “Why do you listen to the people who say I am trying to harm you?
This very day you can see with your own eyes it isn’t true. For the LORD placed you at my mercy back there in the cave. Some of my men told me to kill you, but I spared you. For I said, ‘I will never harm the king—he is the LORD ’s anointed one.’
Look, my father, at what I have in my hand. It is a piece of the hem of your robe! I cut it off, but I didn’t kill you. This proves that I am not trying to harm you and that I have not sinned against you, even though you have been hunting for me to kill me.
“May the LORD judge between us. Perhaps the LORD will punish you for what you are trying to do to me, but I will never harm you.
As that old proverb says, ‘From evil people come evil deeds.’ So you can be sure I will never harm you.
Who is the king of Israel trying to catch anyway? Should he spend his time chasing one who is as worthless as a dead dog or a single flea?
May the LORD therefore judge which of us is right and punish the guilty one. He is my advocate, and he will rescue me from your power!”
When David had finished speaking, Saul called back, “Is that really you, my son David?” Then he began to cry.
And he said to David, “You are a better man than I am, for you have repaid me good for evil.
Yes, you have been amazingly kind to me today, for when the LORD put me in a place where you could have killed me, you didn’t do it.
Who else would let his enemy get away when he had him in his power? May the LORD reward you well for the kindness you have shown me today.
And now I realize that you are surely going to be king, and that the kingdom of Israel will flourish under your rule.
Now swear to me by the LORD that when that happens you will not kill my family and destroy my line of descendants!”
So David promised this to Saul with an oath. Then Saul went home, but David and his men went back to their stronghold.