I'm afraid the premise of the question is flawed, at least for medieval Latin Europe. Medieval people understood very well that polluted water can be boiled to make it safe to drink. A medical treatise that probably dates to the early 14th century, discussing Toulouse, warns not to drink the well water or the local river water "unless it is boiled" (cocinare - to cook). Furthermore, the ale/beer that was ubiquitous in most places north of the Alps was often prepared with water that was merely hot, not boiling.
And for its part, wine was typically consumed after being mixed with significant amounts of water.
In fact, by the early modern era, the people taking the most trouble to avoid polluted water were the commerical beer breweries! (They preferred to relocate to outside cities because the cleaner water made the resulting beer taste better.)
Distillation isn't a straightforward story, either. The straight-up process of distillation as practiced in the medieval Near East and Europe actually produced, in addition to distilled spirits, some alcoholic byproducts that are not good to drink. The method to distill alcohol while eliminating those wasn't developed until the 18th century. So for most of the Middle Ages, believe it or not, distillation remained the province of alchemy, not beverages! By the 14th or 15th century, something resembling brandy was being produced, but it was treated as a medicine and consumed in very small qualities.
In addition to what u/sunagainstgold wrote, the whole idea that people preferred alcohol to water because it was deemed safer is basically false ans stems from the mixture of presentist notion that the preference for drinks other that water must have been cause by sanitary concerns and from the misinterpretation of actual medical advices suggesting that wine is preferable to water. The former was usually caused simply by the ubiquitous preference for something tastier that the most plain drink imaginable (this is why most people today rarely drink mere water) and with lack of tea or coffee (these will gain popularity in Europe only in early 18th and late 16th century respectively) with milk being problematic to store for longer time and requiring a rural area to produce in large quantities, simple fermented drinks like beer, ale, small beer or kvas could be construed as the soda of the previous eras. It should be also noted that kvas is manufactured using cold fermentation (it isn't boiled at any point) and some brewing processes do not use boiling water.
The second issue was a direct product of the medical humour theory that originated in 6th century BCE in Greece and has been prevalent in ancient world since at least 4th century BCE and as both Muslims in Middle East and North Africa and the Christians in continental Europe seemed to resort to ancient works when developing medical theory, humourist ideas were the mainstay of European medicine up to 18th century. Consumption of water, considered to be 'cold' was thought to increase the quantity of 'cold' humour leading to decreased energy, problems with digestion and susceptibility to pulmonary conditions, and thus it was suggested to offset these influences with the ingestion of 'warm' drinks such as wine or mead (metheglin, oximell, hydromel) but conversely people showing excesses of 'hot humours' were advised to reduce the intake of wine. Beer was generally considered 'cold' and thus not recommended to drink in large quantities, although e.g. Thomas Elyot in his 'Castel of Helth' that was published in 1541 notes that beer and ale can be 'a necessary and convenient drink, as well in sickness as in health: considering that barley corn, where of it is made, is commended, and used in medicine, in all parts of the world'* (chapter 20). Earlier, in chapter 18 he states that water is one of the most common and basic drinks that does not seem to have any downsides by itself, provided it is drunk in moderation and even intuitively links the quality of water to its purity (stating that the best water is obtained from rain, followed by springs and 'clean rivers where water runs on large stones or peebles' (presumably , the riverbeds with little to no mud or organic sediment).
*For clarity sake I allowed myself to render the passage using modern English ortography, leaving the original syntax intact.