Early on in our narrative, David runs away into the land of Gath. It turns out, though, that King Achish has heard of David's battle-prowess. David gets worried at this point, perhaps because he thinks Achish will see him as a potential rival. So when the servants drag him before the king, he pretends to be a madman, writing on doorposts and drooling into his beard. The king falls for it hook