"A Psalm of David, when he was in the wilderness of Judah." This is the one that the scripture says (Isaiah 26:16), "Lord, in trouble have they visited thee, they poured out a prayer when thy chastening was upon them." When do the Israelites seek the Lord? When they are in distress, as it says (Psalms 18:7), "In my distress, I called upon the Lord."
When they are in trouble, they seek the Lord, as it says (Psalms 3:1), "A Psalm of David, when he fled from Absalom his son." And it says (Psalms 142:1), "A prayer of David, when he was in the cave." And it says (Psalms 54:1), "A Psalm of David, when the Ziphims came and said to Saul, Doth not David hide himself with us?" And it says (Psalms 57:1), "A Michtam of David, when he fled from Saul in the cave."
And likewise, here when he was in the wilderness of Judah. And it also says (Psalms 18:7), "In my distress, I called upon the Lord, and cried unto my God: he heard my voice out of his temple, and my cry came before him, even into his ears." And it says (Psalms 118:5), "I called upon the Lord in distress: the Lord answered me, and set me in a large place." Therefore, it is said in the wilderness of Judah....