Generally speaking, if you see layers in the rock (sedimentary rocks formed by millenia of deposits of sand, clay, etc., that have compacted under high pressure), there is a high degree of probability that there are pockets of moisture bound inside some of those layers. Heat the rock enough, and the water turns to steam. It has nowhere to go, so it fractures the rock - sometimes explosively.
Other rocks have a more solid appearance - think granite. Those are generally safe, even if they get wet, because they don't have water bound inside. Any moisture that soaked in can escape as steam.
The first year we moved to our property, I didn't know the difference. I dug a firepit in the beach, and lined it with nice, flat rocks that had lots of pretty colored stripes (layers). I built a nice, hot fire with the dry driftwood that was readily to hand. An hour later, we were all taking cover behind a dune in best "Sands of Iwo Jima" fashion.