Rav Aharon of Belz zy”a explained this Medrash by quoting his grandfather, the Sar Shalom of Belz zy”a, who said that “hisbodedus” does not only mean secluding oneself in a place where there are no other people around. Rather, one can do hisbodedus by focusing his thoughts on Hashem, even if he is in a bais medrash surrounded by other people.
Dovid Hamelech was saying that he would plan on going to certain places where he would be alone and where he could connect to Hashem in seclusion. However, his foot took him to the bais medrash because after he contemplated the matter, he realized that even in a crowded bais medrash, surrounded by other people, he could connect to Hashem with his thoughts and become as one with Him.
In this vein, the Ropshitzer Rebbe zy”a said, “One must also be able to do hisbodedus when he is amongst 1,000 men.”
