God's "Middle Knowledge"
This verse is a great example of what's known as God's "Middle Knowledge", or the philosophy of Molinism. This is the view that God knows not only what all people HAVE DONE and WILL YET DO, He also knows what people WOULD DO in different circumstances.
Here, God reports that the citizens of Keilah WOULD give up David and his men, so they leave, giving Keilah no opportunity to do as they intended.
1 Samuel 23:12English Standard Version
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.”