Secondary caves are formed after the surrounding rocks, when the forming of those rocks is already completed. The formation of the rock is the primary stage, the rock is formed without caves. The cave is formed in a secondary stage. Typically there is a long time span between those two processes, for example caves formed in 200 Million years old Jurassic limestone, which were formed during the last 2 Million years.
Most caves on Earth are secondary caves. Probably 90% of all caves are limestone Karst caves, which are secondary caves.
All secondary caves are formed by a mechanism which transports material away. The only possibility to mobilize rock is to make it liquid or gaseous so it can move away. There are only two mechanisms known to produce this effect: solution in water and melting.
The exact way, the rock is dissolved depends on the chemistry of the rock and the water, on the temperature and maybe the pressure. Cave forming processes supported by high temperature are called thermal processes. Karst caves are formed by water with regular temperature using CO2 as agens. Several caves are formed by chemical and biochemical solution based on sulfur, often the sulfuric springs are warm or hot as they have geotheric origin.