When Samuel anointed David to be Israel's king, the young man was given a new heart: "Samuel took the horn of oil, and anointed him in the midst of his brethren: and the spirit of the Lord came upon David from that day forward" (1 Samuel 16:13).
David became a man who was godly, wise, loved and full of the fear of God: "And David behaved himself wisely in all his ways; and the Lord was with him" (18:14).
David was a man of much prayer. He praised the Lord as few people ever have, blessing the heart of God with his songs and psalms. Nobody could have been more intimate with the Lord than David.
David was also a man of great faith. He went on to slay Goliath and become a mighty warrior for Saul. Women sang of his exploits on the battlefield. God's Spirit clearly was upon this man, and the Lord obviously had a plan for his life.
But then Saul came after David with wrath, and David had to flee. He took 400 of his men and fled to the hometown of the giant Goliath, whom he had slain. Talk about an unfaithful act. David had not asked the Lord about this move. On the contrary, he had decided to put his life in the hands of the king of Gath, seeking refuge from him. But in Gath, hostile whispers rose up, "Isn't this the man people sing about? Hasn't he killed thousands of Philistines?" (See 1 Samuel 21:11.)
David was taken to the king. He knew he was trapped, in trouble, so he pretended to be mad, raving incoherently, scratching the walls, spittle running down his beard. He hoped that somehow his "insanity" would deliver him from the clutches of King Achish.
What a poor testimony this was before all his men. Achish looked at David and said, "This man has lost his mind. Get him out of here!"
David was unfaithful at that moment but God was still faithful. He didn't write David off. While David was acting foolishly, God's eternal purpose for him went onward. Saul's kingdom was growing weaker every day and God was moving everything into place to ensure David's blessing.