Milk increases shelf life by holding moisture overall better compared to water. The baking process makes the milk and eggs and other ingredients stable at room temperature.
I make my own cake mix that has powdered skim milk or powdered buttermilk in the dry mix, and then water will suffice to mix it for baking. But the dry milk is still there to give its benefits.
I also bake coconut cake with coconut milk from a tin, no dairy or eggs at all in the batter, it is fine because of the richness of the coconut.
Shanghai, to use water for cake batter you should add 1 tablespoon lemon or lime juice, 1 tablespoon sugar, and 1 tablespoon oil to a measuring cup and then fill to the 1 cup mark with water. Mix with a fork and use in place of milk.