It didn't seem to matter what David did. Everywhere he turned he was running for his life. I'm sure he questioned why God would allow this to happen to him when he didn't do anything wrong.
Even though he probably didn't understand the why of his circumstances, he was learning some very valuable things about the protection and guidance of God. These lessons would help him to become the king that he became.
I Samuel 24 :1-2- And it came to pass, when Saul was returned from following the Philistines, that it was told him, saying, Behold, David is in the wilderness of Engedi. Then Saul took three thousand chosen men out of all Israel, and went to seek David and his men upon the rocks of the wild goats.
Saul had gone to fight with the Philistines, but when the battle was over he was back on David's heels. God was still trying to get Saul to realize that he had done wrong. God was going to use David to help Saul see how far from God's will he had gone.
I Samuel 24:3-4- And he came to the sheepcotes by the way, where was a cave; and Saul went in to cover his feet: and David and his men remained in the sides of the cave. And the men of David said unto him, Behold the day of which the LORD said unto thee, Behold, I will deliver thine enemy into thine hand, that thou mayest do to him as it shall seem good unto thee. Then David arose, and cut off the skirt of Saul's robe privily.
Saul and his men found a cave while they were searching for David. Saul went into the cave to use the bathroom, but he didn't realize that was where David and his men were hiding.
David's men wanted him to kill Saul, but David wouldn't. He sneaked up and cut part of Saul's robe off, and then went back to hiding. Saul had no idea that had even happened.
I Samuel 24:5-7- And it came to pass afterward, that David's heart smote him, because he had cut off Saul's skirt. And he said unto his men, The LORD forbid that I should do this thing unto my master, the LORD'S anointed, to stretch forth mine hand against him, seeing he is the anointed of the LORD. So David stayed his servants with these words, and suffered them not to rise against Saul. But Saul rose up out of the cave, and went on his way.
David's men wanted Saul dead. But, David wouldn't hear of it. He knew that even though Saul was out of the will of God he was still the Lord's anointed- his chosen one to lead Israel at that time. He told his men that he wasn't going to sin against God by killing Saul.
I Samuel 24:8-12- David also arose afterward, and went out of the cave, and cried after Saul, saying, My lord the king. And when Saul looked behind him, David stooped with his face to the earth, and bowed himself. And David said to Saul, Wherefore hearest thou men's words, saying, Behold, David seeketh thy hurt? Behold, this day thine eyes have seen how that the LORD had delivered thee to day into mine hand in the cave: and some bade me kill thee: but mine eye spared thee; and I said, I will not put forth mine hand against my lord; for he is the LORD'S anointed. Moreover, my father, see, yea, see the skirt of thy robe in my hand: for in that I cut off the skirt of thy robe, and killed thee not, know thou and see that there is neither evil nor transgression in mine hand, and I have not sinned against thee; yet thou huntest my soul to take it. The LORD judge between me and thee, and the LORD avenge me of thee: but mine hand shall not be upon thee.
David went out of the cave after Saul had left and called him. He showed him the piece of his robe that he had cut off and told Saul that he could have killed him, but didn't. He wanted Saul to understand that he wasn't going about trying to kill him or take the kingdom away from him.
I Samuel 24:16-22- And it came to pass, when David had made an end of speaking these words unto Saul, that Saul said, Is this thy voice, my son David? And Saul lifted up his voice, and wept. And he said to David, Thou art more righteous than I: for thou hast rewarded me good, whereas I have rewarded thee evil. And thou hast shewed this day how that thou hast dealt well with me: forasmuch as when the LORD had delivered me into thine hand, thou killedst me not. For if a man find his enemy, will he let him go well away? wherefore the LORD reward thee good for that thou hast done unto me this day. And now, behold, I know well that thou shalt surely be king, and that the kingdom of Israel shall be established in thine hand. Swear now therefore unto me by the LORD, that thou wilt not cut off my seed after me, and that thou wilt not destroy my name out of my father's house. And David sware unto Saul. And Saul went home; but David and his men gat them up unto the hold.
Saul began to realize the David wasn't trying to kill him. Do you think that meant that Saul would stop trying to kill him? This time Saul did stop. He made David promise not to destroy his family when he became king. Then, he went back to his home.