H2O(l) + CO2(g) ↔ H2CO3(aq)
When this slightly acidic water moves through fractures in limestone bedrock, it slowly dissolves away the mineral calcite (limestone is a rock composed of the mineral calcite - CaCO3).
CaCO3(s) + H2CO3(aq) ↔ Ca2+(aq) + 2 HCO3-(aq)
This results in calcium (Ca2+) and bicarbonate (HCO3-) ions dissolved in the water. By this process, fractures in the limestone may gradually be dissolved into cave passages. After the formation of a cave, water flowing from a fracture into the void of a cave will release some carbon dioxide out of solution. It will do this in an effort to reach equilibrium with the air in the cave. In doing so, it will also re-precipitate calcite.
Ca2+(aq) + 2 HCO3-(aq) ↔ CaCO3(s) + CO2(g) + H2O(l)
This is how speleothems (cave formations like stalactites, stalagmites, flowstone, etc.) form in caves.
Speleothems can form in places other than natural caves. I was in an old cement mine recently (Widow Jane Mine in Rosendale, NY) and observed some neat rimstone formations there on the slightly sloped floor (the mine followed the dipping bedding planes of the carbonate rock layers).
My daughter took this picture of rimstone formations in the mine
Rimstone is a type of speleothem (it's very common in natural caves as well) which forms when water saturated with calcium (Ca2+) and bicarbonate (HCO3-) ions flows over the uneven floor of a cave (or mine, in this case). The turbulence from flowing over an irregular surface causes carbon dioxide to come out solution precipitating calcite dams over the irregularities. Over time, you get little pools separated by the rimstone dams. Pebbles in the pools also get coated with calcite to form what are called cave pearls.
The next picture just gives an idea of the size of the rimstone formations. They're next to me on the floor. They're small but neat little features.
God damn I look stupid in that picture. To be fair, it was taken with a flash in a dark part of the mine.