Good question. The answer, in short, is David was (or at least he appeared to be at that time) an angel from God to King Achish.
David's alliance (some would say dalliance!) with Achish was likely not God's will for David and his 600 men, since Achish was a Philistine, a leader of the people whom Israel was to have wiped off the face of the earth. Evidently, however, David lacked faith in YHWH at this time, thinking he had no other option but to align himself with the king of Gath (1 Sam 27:1), not realizing God could have protected him wherever he went. Remember, David had learned--either before or after this incident--God could provide a table for him in the presence of his enemies (see Psalm 23:5).
Nevertheless, though David's motives in his dealings with Lachish were far from pure--deceptive, in fact (27:9-12), Achish naively, but providentially, trusted David and allowed him and his men to live amongst his people for almost a year and a half (27:7). That is why in chapter 29, Achish considered David to be an angel sent by God.
David had an enviable reputation at this time for his military exploits, including his run-ins with Philistines:
"'Is this not David, of whom they sing in the dances, saying, "Saul has slain his thousands, And David his ten thousands"?" (29:5).
Achish was undoubtedly grateful for his alliance with David, who could just as easily have been a formidable enemy. He trusted David sufficiently to allow David and his men to settle in Ziklag, which was in Philistine territory. David could thus come and go as he pleased without coming under suspicion of at least the people under King Achish's control.
Unbeknownst to Achish, however, while David was in Ziklag, he and his men fought against the Philistines who lived southwest of Ziklag. Again, David deceived Achish by giving him the impression he had gone out to battle against his own people in Judah.
Achish believed David's story and thought David had now truly made himself odious to his own people (27:12). Achish's naiveté stood David in good stead later on, so much so that Achish considered David to be an angel from God (29:9).
In conclusion, David's lies and deceptions were not sinful, only good military and political machinations. David's real sin lay in not trusting God, thinking he had no other choice but to align himself with King Achish. Believers always have a choice. We can either to do things God's way or our way. When we choose the latter, we set ourselves up for trouble of our own making.