Running for his life from the deranged King Saul (bipolar disorder?), David tries to go to ground in a Philistine town called Gath--a place which has less than friendly feelings toward David, considering he killed Gath's most famous warrior, Goliath. With a slingshot. When he was, like, 13. And then chopped off Goliath's head and took it home as a trophy. And is, in fact, now carrying Goliath's sword.
Why David thought Gath would be a good place to lie low...the Bible doesn't say. Anyway, right away they recognize him. Duh.
So what does David do? The only natural thing, of course. He pretends to be stark raving mad. Pounding his head on the city gate, foaming at the mouth, singing Lady Gaga songs off-key, etc. Which leads the King of Gath, Achish, to, um, lose it:
"Can't you see this guy is a freaking loon job? Why'd you let him in here? What, you think I don't have enough crazy people around this place? So, what, I need one more, for good measure? Get this psycho out of here!"
(1 Samuel 21:10-15)