Narrated Abu Hurairah (radi Allahu anhu):
“The Prophet (sal Allahu alaihi wa sallam) forbade the drinking of water (directly) from the mouth of a water-skin.” [Sahih Bukhari]
In the time of the Prophet (sal Allahu alaihi wa sallam) water used to be stored in leather bags called water-skins. Our mouths are ecosystems for a variety of bacteria, fungi, protozoa and viruses.
This prohibition might be to prevent people from contaminating the main container.
To drink directly from the water-skin would be akin to putting one’s mouth on the nozzle of a water-cooler. The nozzle is not as easily or frequently washed as a glass. Thus, colonies of microbes would build up on it.