Cave Castle are castles built into caves. Unlike cave houses, which are mostly artificial dug outs, cave castles are typically built into natural caves. However, the castle is artificial and the caves are often artificially widened, so they are listed here with subterranea.
The word castle often implies something like medieval castles in Europe, so the first idea is that cave castles are found only in Europe. But there are cave castles everywhere on earth where people lived. It seems most cultures on earth needed protection, against enemies or against wild animals. A castle is a small village with a wall around to keep others outside.
So why build castles into caves? That's simple: because it means less work. If you use a cave, typically an entrance portal in a cliff face, you have numerous advantages: The rear side is protected by the mountain itself, and there is shelter by the cave roof, so it is not necessary to build a massive back side or a stable roof. And the front is often high above the neighbourhood, so fortifications on that side are also easier to build.
But there are still more advantages of caves. Many caves have a cave river or some kind of flowing water, which could be used for collecting drinking water. Because this spring is inside the cave, it can not be poisoned by enemies. And some of those caves have other entrances, which - if known only to the people inside the castle - can be used to refill the stock, get more defenders or flee, if necessary. Predjamski Grad in Slovenia has such a back entrance, which was used by the knight Erazmov, who got fresh vegetables and fruits from villages nearby and threw them down to the besiegers to demonstrate his good stock.