Disclaimer: This is more of a scientific theory not relating to any religion. Of course still, we believe that God created everything including the ocean.
After the Earth’s surface had cooled to a temperature below the boiling point of water, rain began to fall and continued to fall for how many centuries. As the water drained into the great hollows in the Earth’s surface, the ocean came into existence. The forces of gravity prevented the water from leaving the planet, which is beneficial for humans to live.