מַשְׂכִּ֥יל לְדָוִ֑ד בִּהְיוֹת֖וֹ בַמְּעָרָ֣ה תְפִלָּֽה׃
Isang Maskil ni David, noong siya ay nasa yungib; isang panalangin.
Midrash Tehillim
"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....
Midrash Tehillim
Understanding of David during his prayer in the cave. Solomon said in Proverbs 18:10, "The name of the Lord is a strong tower; the righteous run to it and are safe." When the righteous are in distress, they only focus on the Lord. The scripture also says in Psalm 34:2, "I will bless the Lord at all times; His praise shall continually be in my mouth." When David fled from Absalom, he only sang to the Lord. Similarly, when he was in the wilderness of Judah, he only mentioned the Lord. In every trouble he faced, he trusted in the Lord. And when he was in the cave, he called only upon the Lord, as it says in Psalm 142:4, "I cry out to You, O Lord; I say, ‘You are my refuge, My portion in the land of the living.’" What does it mean that David had "understanding"? When Saul and David were in the cave, David knew and saw that no one was standing with him in his wealth, wisdom, or strength. Therefore, his only recourse was to pray. David understood and said that he had no good except for prayer. Therefore, it is said, "Understanding of David" (in reference to Psalm 142) and so on....