English Basic Explanation - Chapter 54
The second verse of chapter 54 informs us that David composed this brief prayer when the people of Zif reported to King Shaul that he had been hiding among them. In the Book of Shemuel I (23:14), we read that David and his men remained in the wilderness of Zif (a region within the territory of the tribe of Yehuda) for an extended period of time where they hid from Shaul, who pursued David. But the people of the area betrayed David by reporting his whereabouts to Shaul, and then proceeded to send spies to follow David's trail and thus assist Shaul in his attempt to capture him.
David here attributes the cruelty of the people of Zif to the fact that "they did not place God opposite them" (verse 5). They disregarded their accountability to God and thus felt no compunctions about betraying David to earn the king's favor. Nor did they realize that their efforts are doomed to failure due to God's assistance that has accompanied David throughout his flight from Shaul (verse 6).
To more fully appreciate David's frame of mind when composing this Psalm, we must consider his situation before the people of Zif reported his location to Shaul. During David's stay in Zif, we are told (Shemuel I 23:14), Shaul had been unsuccessful in his attempts to locate David, and it thus appears that Zif had provided David with his long-awaited place of refuge and security. Moreover, the verse states (Shemuel I 23:19) that when the people Zif approached Shaul with the information concerning David's whereabouts, Shaul was in Giv'a. As the Malbim notes (in his commentary to Shemuel I), Giv'a was where Shaul lived, and it thus appears that Shaul had already despaired from pursuing David and returned home. Just as it seemed that David could finally enjoy a semblance of peace and security, the people of Zif reported to Shaul and David was once again forced to flee.
This sudden and drastic turn of events could have easily led David to despair. But rather than reflect on his frustrations, David instead looked to the assistance God had lent him in the past as a source of encouragement. As he declares in the final verse of this Psalm, God has already saved him on numerous occasions, and he thus confidently anticipates God's intervention to rescue him from his current crisis, as well.