David took note of these remarks and became very much afraid of Achish, king of Gath.
One wonders why was David so afraid. According to David Roper this was David’s testing.
Just about the time I think I've got it all together, some unsightly emotional display, some inappropriate reaction, some other embarrassing behavior blows my cover and I have that horrible experience of being found out. It's humiliating! But humiliation is good for the soul. Through it God deals with our self-admiration and pride. Without it we could never make the most of our lives. The trouble with us is that we want to be tremendously important. It's a terrible trait, the essential vice, the utmost evil. It's the sin that turned the devil into the demon he became. Obscurity and humility, on the other hand, release God's greatness. It is the basis of our life with God and our usefulness in this world. Thomas à Kempis wrote, "The more humble a man is in himself, and the more subject unto God; so much more prudent shall he be in all his affairs, and enjoy greater peace and quietness of heart." Because ambition and pride is the center of our resistance to God and the source of so much unhappiness, "God opposes the proud" (James 4:6); he brings us to our knees, where He can then begin to do something with us.
David fled from Saul and went to Achish king of Gath. But the servants of Achish said to him, "Isn't this David, the king of the land? Isn't he the one they sing about in their dances: 'Saul has slain his thousands, and David his tens of thousands'?" David took these words to heart and was very much afraid of Achish king of Gath. So he pretended to be insane in their presence; and while he was in their hands he acted like a madman, making marks on the doors of the gate and letting saliva run down his beard. Achish said to his servants, "Look at the man! He is insane! Why bring him to me? Am I so short of madmen that you have to bring this fellow here to carry on like this in front of me? Must this [mad] man come into my house?" David [then] left Gath and escaped to the cave of Adullam (1 Samuel 21:10-22:1). David fled south from Nob — with Saul in hot pursuit — and he made his way across the Judean hills and through the Valley of Elah where a few years before he had engaged Goliath in combat. It was to Gath — the home of his enemies — that David now turned for shelter from Saul. I don't know what possessed David to flee to Gath. Perhaps he thought he wouldn't be recognized, since this was several years after his encounter with Goliath, and he had grown to manhood. Perhaps he disguised himself in some way. But David was instantly recognized, and his presence was reported to king Achish of Gath: "Isn't this David, the king of the land? Isn't he the one they sing about in their dances: 'Saul has slain his thousands, and David his tens of thousands'?" The phrase "they sing" could be translated, "they still sing," suggesting a popular tune. David's fame was celebrated everywhere — even in Philistia. You have to understand the implications of this song. David had slain his ten thousands of Philistines; his fame had been established at the expense of bereaved Philistine women and children. Here was an opportunity to take vengeance. Furthermore, he was considered "the king of the land [of Israel]." By some means David became aware that he had been found out, and that he was facing imprisonment and death, so David lost his nerve (see Psalm 34 and 56). Motivated by sheer terror, David pretended to go mad, foaming at the mouth and scrawling crazy slogans on the walls. According to the title of Psalm 56 the Philistines "seized him" and brought him to Achish, who dismissed him with the contemptuous remark: "Behold, you see a madman! Why have you brought him to me? Am I lacking madmen that you have brought this to ply his madness against me? Must this come into my house?" The word translated "mad man" (21:15), used three times by Achish, suggests something other than insanity. The word in other Near Eastern languages means "highly aggressive" — violent and dangerous — which gives added force to the king's remark: ". . . you have brought this to ply his madness [ravings] against me?" Achish was afraid of David. The title to Psalm 34 supplies the conclusion of the matter: Achish "drove him away," out of his court and out of town — David, run out of town on a rail, utterly humiliated. David, the tough guy, the hero of Israel, the man they celebrated in song and dance had wimped out in the face of physical danger and made an utter fool of himself. With no place else to go, unwelcome in both Israel and Philistia, David fled into a labyrinth of broken ridges and rimrock about three miles from Gath and crept into a cave. The cavern in which he found refuge was called the Cave of Adullum (Adullam means refuge). It can't be located with certainty, but the traditional site is a dark vault located on a shelf at the top of a near-perpendicular cliff. In that dark place — humiliated, crushed, alone — he wrote Psalm 34 and Psalm 56. He was at his nadir. In that dark place David cried out to God: "This poor [humiliated] man called, and the LORD heard him." There he learned that "The LORD is close to the brokenhearted and saves those who are crushed in spirit" (34:6, 18). Lord Byron wrote from Reading Jail, "How else but through a broken heart can Lord Christ enter in?" Furthermore, David learned to boast in the Lord rather than in his own ability (34:2). Through shame and disgrace he became a more modest man — one whom God could shape and use.