When we think about a shepherd and sheep, we have to think of an arid environment, like modern-day Palestine, and not the lush green fields of Kansas. Look at these pictures of the oasis in a desert. That is where we can imagine the shepherd in Psalm 23 is guiding the sheep for food and water: https://talkofjesus.com/wp-content/uploads/2016/12/Bethlehem-hills-in-palestinian-region-of-Israel-2016.png.
Valleys can be dangerous places. In these high, desert environments, valleys typically have more vegetation, and predators can see trapped prey from the hilltops. But in these valleys are streams and vegetation for food. The sheep find provision in valleys, and the shepherd guards them from attack. The shepherd knows what the sheep need and guides them there.