When Earth was forming, it was a hot ball of volcanism. It is this volcanism as well as early microbes that released gases to build the Early atmosphere, made of water vapor (H2O), carbon monoxide (CO), carbon dioxide (CO2), hydrochloric acid (HCl), methane (CH4), ammonia (NH3), nitrogen (N2), and sulfur gases. With almost no oxygen in existence.
The water could have been sourced from meteorites and comets which may have fell to Earth during it's early formation in the violent, early days of the forming solar system.
Its believed the planet began to cool, most likely due to a decrease in volcanism.
As the planet cooled, the water vapor in the atmosphere began to condense and fall to Earth, as lakes and liquid water formed, this dissolved carbon dioxide in the atmosphere helping to thin the atmosphere and reduce the heat for more water vapor to condense.
This CO2 would have also been trapped/stored in minerals at the Earth surface, notably Calcium Silicate (CaSiO3) which when it reacted with the carbon dioxide, it removed and trapped the carbon, producing Calcium Carbonate (CaCO3) and Silicon dioxide (SiO2), helping further remove carbon dioxide from the atmosphere.
It is at this time it is widely believed in the hazardous waters of early Earth, small algal-like plant organisms evolved. Increasing the oxygen content of the atmosphere and trapping/removing carbon as well. This increase in oxygen helped to remove the ammonia and methane in the atmosphere, reacting with methane to produce water, carbon dioxide and hydrogen (2CH4 + 3O2 -> 2H2O + 2CO2 + 2H2), and with ammonia to produce nitrogen, water and hydrogen (2NH3 + O2 -> N2 + 2H20 + H2).
With the thinner atmosphere, the planet cooled further and led to more condensation of liquid water. Leading to the planet we know today.
Although water could have come via meteorites and comets, it would have been a trace amount, even if the comet/meteor was water rich, it would have had to be hundreds of thousands to bring enough water to Earth, so it is more widely believed that most of the water on Earth was here since it's formation.
Hope this helps!