It was reported to David: "Look, the Philistines are fighting against Keilah and raiding the threshing floors."
References for 1 Samuel 23:1
So David inquired of the Lord: "Should I launch an attack against these Philistines?" The Lord answered David, "Launch an attack against the Philistines and rescue Keilah."
But David's men said to him, "Look, we're afraid here in Judah; how much more if we go to Keilah against the Philistine forces!"
Once again, David inquired of the Lord, and the Lord answered him: "Go at once to Keilah, for I will hand the Philistines over to you.
Then David and his men went to Keilah, fought against the Philistines, drove their livestock away, and inflicted heavy losses on them. So David rescued the inhabitants of Keilah.
Abiathar son of Ahimelech fled to David at Keilah, and he brought an ephod with him.
References for 1 Samuel 23:6
When it was reported to Saul that David had gone to Keilah, he said, "God has handed him over to me, for he has trapped himself by entering a town with barred gates."
Then Saul summoned all the troops to go to war at Keilah and besiege David and his men.
When David learned that Saul was plotting evil against him, he said to Abiathar the priest, "Bring the ephod."
Then David said, "Lord God of Israel, Your servant has heard that Saul intends to come to Keilah and destroy the town because of me.
Will the citizens of Keilah hand me over to him? Will Saul come down as Your servant has heard? Lord God of Israel, please tell Your servant." The Lord answered, "He will come down."
Then David asked, "Will the citizens of Keilah hand me and my men over to Saul?" "They will," the Lord responded.
So David and his men, numbering about 600, left Keilah at once and moved from place to place. When it was reported to Saul that David had escaped from Keilah, he called off the expedition.
David then stayed in the wilderness strongholds and in the hill country of the Wilderness of Ziph. Saul searched for him every day, but God did not hand David over to him.