Like Psalm 56, this psalm is called a miktam.
David was sheltering in a cave. This probably happened after the events in Gath when he was caught by the Philistines and then broke down. Psalm 57 is a psalm of praise addressed to the throne of Yahweh.
It is thought that the cave in question could be the cave of Adullam. David was not alone but was accompanied by a following which included his brothers (1 Samuel 22:1; 2 Samuel 23:13–17). These were people who were grieved by the conditions in Israel under Saul.
1 Be merciful to me, O God, be merciful to me, for in you my soul takes refuge; in the shadow of your wings I will take refuge, till the storms of destruction pass by.