David thought, One day I will be destroyed by Saul's power. The best thing for me to do is to escape to Philistine territory. Then Saul will give up looking for me in Israelite territory, and I will escape his power.
References for 1 Samuel 27:1
So David set out with his six hundred soldiers and went to Achish, Maoch's son and Gath's king.
David and his soldiers stayed there at Gath with Achish. Each man had his family with him, and David had his two wives, Ahinoam from Jezreel and Abigail, Nabal's widow from Carmel.
When Saul was told that David had fled to Gath, he didn't pursue him anymore.
Then David said to Achish, "If you approve of me, please give me a place in one of the towns in the country so I can live there. Why should I, your servant, live in the capital city with you?"
So Achish gave the town of Ziklag to David at that time. That's why Ziklag has belonged to the kings of Judah until now.
David lived in the Philistine countryside for a total of one year and four months.
David and his soldiers went out on raids against the Geshurites, the Girzites, and the Amalekites. They were the people who lived in the land from Telam to Shur all the way to the land of Egypt.
References for 1 Samuel 27:8
When David attacked an area, he wouldn't leave anyone alive, man or woman. He would take the sheep, the cattle, the donkeys, the camels, and the clothes and would then go back to Achish.
When Achish asked, "Where did you raid today?" David would say, "The southern plain of Judah," or "The southern plain of the Jerahmeelites," or "The southern plain of the Kenites."
References for 1 Samuel 27:10
David never spared a man or woman so they could be brought back alive to Gath. "Otherwise," he said, "they might talk about us, and say, ‘David did this or that.'" So this was David's practice during the entire time he lived in the Philistine countryside.
Achish trusted David, thinking, David has alienated himself so badly from his own people in Israel that he'll serve me forever.