The forming of karst caves is very complicated and it is still a topic of geological research. But some basic aspects are very simple: water containing carbon dioxide CO2 is able to dissolve limestone.
Unlike with salt and gypsum, water is not able to dissolve limestone without a little help. And this helper is carbon dioxide CO2. Carbon dioxide is a very common gas, you know it from sparkling water, softdrinks, and beer. They all contain it, it makes them bubbling. Natural water also contains CO2, but much much less, as it is normally not bubbling. Just fill some water in a bottle and after some hours you will see small gas bubbles at the glas of the bottle.
Carbon dioxide is in the the air, about 0.03% of our atmosphere is this gas. Animals and humans breathe air, consume (burn) the oxygen and exhale carbon dioxide. Many carbon dioxide is produced by biologic processes in the soil. When the rain water falls, it first absorbs some carbon dioxide from the atmosphere, but then, oozing through the soil, it absorbs much more biogene CO2.
In the water, the CO2 breaks up in two pieces, thus producing a (very weak) acid:
When this water gets in contact with limestone, the acid dissolves the limestone.
This happens on the rock surface, just at the border between rock and soil. But when the limestone, which is originally water proof, contains cracks produced by tectonic forces - which is very common - the water oozes into the rock and starts to widen the cracks and solute caves inside the layers.
With the small amount of CO2, the amount of dissolved limestone is very small and it takes several ten thousand years or more to form a cave.
The limestone in the spring water in karst areas is very common and well known to the people living in those areas. If you heat this water (e.g. for making coffee, in the washing machine,...) the CO2 escapes and the limestone gets solid again. This process is similar to the forming of many speleothems in caves, like drip stones.