Water is formed from hydrogen and oxygen . So any planet which has both hydrogen and oxygen can contain water.
However , the distance of Earth from Sun causes the temperature to remain in range in which water can freely exist in liquid state. If a planet was too hot then even when water is present , it will be in gaseous form of water vapours . On the other hand If planet was too cold then water will be in form of Ice.
Hence water on Earth is due to its components - Hydrogen and Oxygen but it exist in Liquid form due to favourable temperature range.
Water is one of the most abundant substances in the universe and its components hydrogen and oxygen are some of the most abundant elements in the universe.
Theoretically one of the most likely ways water appeared on Earth is through comet collisions early in Earth's history while the Earth was still forming.