Yahweh told Moses to do this so that the rock would produce water for the people and their cattle to drink.