Before David became King and united the Israelites under a common head, he went through some very fearful and dangerous situations. These can all be found in the Bible, in the book of I Samuel. Consequently, David gathered a band of outlaws around him and was always on the move. Some of the places he fled to turned out to be traps for both David and those who trusted him.
Psalm 56 was written whilst he was living among the Philistines, in the region we now call the Gaza Strip. To avoid imprisonment and death, he feigned insanity and was dismissed by Achish, King of Gath.
Isobel and Pauline elaborate on Psalm 56 in this episode of Nightcap, to be found on the following URL.