The cross-section of the honeycomb is hexagonal, essentially. It’s because it is the only natural grid where the adjacent cells are all equidistant, in 2D geometry. The honey cells are round (cylindrical) and staggered (which is better structurally than a square grid) and the hexagonal honeycomb between them is just the natural shape that results in geometrically.
However, how insects make their hives is a complete mystery to conventional science. No one knows how hundreds or thousands of individuals with speck-sized brains can possibly coordinate to make (or repair) a complex structure like that. No one really understands many large-scale coordination like that, even the growth of an animal or plant body from cells all with the same DNA. There is no physical science explanation possible, really. We just know that groups of cells or insects or birds or whatever seem to have some features of group organization and shared consciousness, or just plan or hologram or something.