As lava/magma cools & contracts it can form polygon stone columns.
Columnar jointing is a rock formation where fractures (joints) occur in cooling volcanic rock. As the lava/magma cools from the outside inward it shrinks towards center points. This shrinking then continues from the top down forming columns of rock. These stone columns are frequently hexagonal with six sides (a shape very common in nature) but other numbers of sides occur as well.
These rock formations can be straight vertical columns (the Giant’s Causeway, Devil’s Tower, Svartifoss, etc.) but can also form with sideways irregularities due to how the molten rock moved and cooled (such as Alcantara Gorge where the lava cooled diagonally).
Rock Folktales
Because they look carved and intentionally organized they don’t seem natural. Cultures around the world have come up with a variety of explanations for these rock formations. Devil’s Tower in Wyoming is a striking example of columnar jointing which features the tallest columns in the world. Its name varies by different Native American groups but it tends to be versions of “Bear’s Home”. According to tradition, as children were fleeing a great bear (or bears) the animal’s claws dragged down the rock face, carving the columns we see today.
The Giant’s Causeway in Northern Ireland is perhaps the most famous example of columnar jointing. As the legend goes the causeway was formed by Irish giant (or just regular sized superhero) Fionn mac Cumhaill (Finn MacCool). He built a series of stepping stones to connect Ireland to Scotland. Longer story short, the Scottish giant Benandonner smashed the causeway during his retreat from Ireland back to Scotland. Today the remnants of this “causeway” are the rocks at the Giant’s Causeway and a similar rock formation on the Isle of Staffa (the most famous part of Staffa is Fingal’s Cave, named after Fionn, which was a very popular source of inspiration for the arts in the 19th century).
In Iceland, a volcanic hotspot in the past as well as today, there are several examples of rock columns. The rock formations along the black sand beach of Reynisfjara are said to be two trolls who were dragging a three-masted ship to land. As they fought over the ship they lost track of time and dawn came, turning the trolls into the rock columns. The rock columns at Svartifoss were the inspiration for Hallgrímskirkja church in the center of Reykjavik. The hexagonal shapes of Svartifoss also influenced the design of the Harpa concert hall.
Added info: Columnar joint formations are not limited to Earth. The volcanism involved in the formation of Mars also created stone columns in much the same way we have them here.