1 Samuel 22:1 David left Gath and escaped to the cave of Adullam.
Adullam was located in Judah.
When his brothers and his father’s household heard about it, they went down to him there. 2All those who were in distress or in debt or discontented gathered around him, and he became their commander. About four hundred men were with him.
3From there David went to Mizpah in Moab and said to the king of Moab, “Would you let my father and mother come and stay with you until I learn what God will do for me?” 4So he left them with the king of Moab, and they stayed with him as long as David was in the stronghold.
This stronghold is not the cave of Adullam. It's probably located in Moab.
5 But the prophet Gad said to David, “Do not stay in the stronghold. Go into the land of Judah.” So David left and went to the forest of Hereth.
Gad's advice was good. Being the future king, David should not be away from his own country for the long term. David gradually built up his power base in Judah. Some months later in
2 Samuel 2:
1In the course of time, David inquired of the Lord. “Shall I go up to one of the towns of Judah?” he asked.
The Lord said, “Go up.”
David asked, “Where shall I go?”
“To Hebron,” the Lord answered.