Trial by water was one option available under trials by ordeal in Medieval Europe. Trials by ordeal, like trials by combat, come from ancient Germanic law customs. I'll mostly write here about its use in the High Middle Ages in Britain.
Trials by ordeal generally came in two forms: trial by fire, or trial by water. In the case of trial by fire, the accused held a red-hot iron for a prescribed length of time, after which the healing wound would be examined to determine guilt. Similarly, in trial by water, the accused would be thrown into a body of water: sinking meant innocence, and floating meant guilt. The concept behind trials by ordeal were that God would intervene to display the guilt or innocence of the accused party. Invoking the sacred would often include a priest exorcising or blessing the iron or water to be used in such trials.
Trial by fire was considered the more prestigious of the ordeals: it was used for women, and more accused males of higher social status. Trial by water was more often used on serfs (but likewise seems to have been the vastly more common type of ordeal, on the scale of something like 83% to 17% trials by fire in England in the 12th century. Trials by ordeal were not used specifically in witchcraft cases, which in the High Middle Ages were practically nonexistent anyway (witchcraft hysteria is more a product of the Late Medieval and Early Modern Period). As Robert Bartlett describes it:
Unlike trial by battle, the unilateral ordeals of iron and water were employed in England only in criminal cases ... Henry II made widespread use of them in the drive against crime initiated by his Assize of Clarendon in 1166. According to this enactment, juries of twelve men of every hundred and four men of every township were to supply the names of anyone who, within the last twelve years, had been accused or was suspected of robbery, murder, or theft, or of harbouring robbers, murderers, or thieves. The sheriffs were to seize those accused or suspected and bring them before the royal justice. Unless they had been caught with stolen goods and were of bad repute, they could undergo trial by cold water. If they failed, they lost a foot (and, after 1176, their right hand too). If they passed the ordeal but had a bad reputation, they had to go into life-long exile from the kingdom.
Interestingly, the records from this period in England indicate that something like two thirds of those subjected to trial by water passed, ie they were judged to have sank, and therefore were not guilty. Bartlett, however, notes that what passes as "sinking" or "floating" can be very arbitrary concepts: "To place the case before God was also to put it into the hands of a small body of men with opinions and feelings of their own."
I cannot really speak to how common the practice was for witchcraft trials, as those tended to be more common in later time periods (and mostly in other parts of Europe, such as the Low Countries, that used civil law and inquisitorial prosecution). Nor can I speak to when the idea became a common modernist myth that witch trials involved trial by water (usually with the Catch-22 idea that an innocent person would sink and drown, while a guilty person would float and then be executed). But it seems to be mostly that. While trials by ordeal are very foreign to modern people, and invoke the supernatural to a degree that would make us comfortable, there were rules behind their use, and most of those who submitted to such trials appear to have been acquitted.
Mostly from Robert Bartlett, England Under the Norman and Angevin Kings, 1075-1225