1 Samuel 27:5
And David said unto Achish, If I have now found grace in thine eyes, let them give me a place in some town in the country, that I may dwell there: for why should thy servant dwell in the royal city with thee? And David said unto Achish, If I have now found grace in thine eyes, let them give me a place in some town in the country, that I may dwell there: for why should thy servant dwell in the royal city with thee?
David asked Achish to have a place given him in some town in the country to dwell in, rather than remaining with the king in the royal city. In part he did this to avoid the envy he had experienced at Saul's court. More importantly, he believed that dwelling apart from those devoted to idolatry and sin would shield him and his men from their influence and give them greater freedom to worship God. Achish granted his request by giving him Ziklag as a possession.
The settlement appeared permanent and was made under Achish's promised protection. David brought his household and his possessions with him into Philistia. The Philistines welcomed him from self-interest, hoping to separate his forces from Saul's army and to persuade him to fight against Saul and Israel. In making this move he placed himself under Philistine protection without seeking God's counsel. His later deception repaid the Philistines' favor poorly.
By prudent and humble conduct he was at peace even with his enemies. He remained among the Philistines until Saul died. Though he knew God had chosen him to rule Israel, he would not kill Saul, whom God had anointed.