God clearly said that the men of Keilah would surrender David (1 Samuel 23:12), but then David leaves the city in the next verse. If God is never wrong, then why did the men of Keilah not surrender David to Saul like God said they would?
Let’s examine the context:
1 Samuel 23:7-14 (ESV)
7 Now it was told Saul that David had come to Keilah. And Saul said, “God has given him into my hand, for he has shut himself in by entering a town that has gates and bars.”
8 And Saul summoned all the people to war, to go down to Keilah, to besiege David and his men.
9 David knew that Saul was plotting harm against him. And he said to Abiathar the priest, “Bring the ephod here.”
10 Then said David, “O Lord, the God of Israel, your servant has surely heard that Saul seeks to come to Keilah, to destroy the city on my account.
11 Will the men of Keilah surrender me into his hand? Will Saul come down, as your servant has heard? O Lord, the God of Israel, please tell your servant.” And the Lord said, “He will come down.”
12 Then David said, “Will the men of Keilah surrender me and my men into the hand of Saul?” And the Lord said, “They will surrender you.”
13 Then David and his men, who were about six hundred, arose and departed from Keilah, and they went wherever they could go. When Saul was told that David had escaped from Keilah, he gave up the expedition.
14 And David remained in the strongholds in the wilderness, in the hill country of the wilderness of Ziph. And Saul sought him every day, but God did not give him into his hand.
Upon hearing that Saul was on his way, David sought out God for a specific reason: guidance as to what to do. Thus, he asked God if Keilah would turn him over to Saul and if Saul was actually going to come down. God replied that Saul was actually on his way and that Keilah would surrender David over to him. Thus, God gave David the guidance he was seeking. Now David knew what to do, and he did it. He left immediately, and thus escaped Saul.
God was not telling David, “This is definitely what will happen, no matter what.” God was telling David, “If you stay in Keilah, this is what will happen.”