Underwater caves are formed through the dissolution of soluble rock by acidic groundwater, followed by flooding of the caves with water due to changes in sea level and other geological forces.