This is one of those areas where if you read it closely you will see its a pretty commonsense type of thing.
Because of persecution from Saul, David had to leave his homeland. He went to live with the Philistines ( his old enemies). To convince the Philistines that he was on their team he would say ohhh i went and attacked Southern Judah today! thats where i got all these things
you can see this in (1 sam 27:10).
This appeased the King of his new home Achish. Kind of like, i know your serious because you have begun attacking your own people, i will trust you.
But the whole time David was ACTUALLY attacking his enemies, not the people of Judah like he told the king. He would kill everyone sort of like a "dead men tell no tales/leave no witnesses" sort of thing. The idea being that because no one was left alive, there would be no one to say "Hey David attacked us, and not Judah like he told the king!"
In this way David was able to survive outside of the Kingdom of Israel where he was persecuted by Saul, yet continue his Military Campaign against Israels enemies.
If you read it slowly and watch the names it makes sense (its easy to skip over all the names in the old testament i know).