Theres a lot of disagreement about how earth got its water, especially as the planets closer and further from the sun dont seem to have much water.
Earth has water for 2 main reasons.
Rocky comets bring water to the inner solar system. As they reach the asteroid belt they begin to form tails. Further away, there isnt enough solar wind density to create tails. There is water in these tails because the oxygen atoms in the rocky comets combines with the protons (hydrogen nuclei) in the solar wind. Its a chemical reaction that takes place at the surface. Comets dont actually contain significant amounts of water molecules.
Theres nothing magical or unbelievable about this way of making molecules. Plants make sugars in an analogous way. Using 2 different sources of materials, they combine hydrogen from liquid water with carbon from CO2 in the air.
These water molecules are created in large amounts and disperse in the inner solar system, to be collected by whatever passes through them. Such as earth.
In the past there was a time when a lot of rocky bodies entering the inner solar system and leaving behind water vapor. Its called the heavy bombardment as earth was hit so often during that time. Also a lot of water vapor was generated by their comet tails. A lot of earths water was collected during this time.
Second, earth is in the suns “condensation zone”, where its not too hot. Closer to the sun, water remains in the gas phase and easily pushed outward by the solar wind. further away, the solar wind becomes too weak and cool and the polar water molecules begin to interact and are much easier for electromagnetically active planets to collect.
The earth collected so much of the solar systems water because it is at a suitable distance from the sun to collect the water chemically generated by comets. A process that can now be observed in comet 67P that is a big rock producing jets of water vapor.