You get hexagons because of close-packing.[1] Circles (or a 2D array of spheres) of the same size fit closest together when they are arranged in a hexagonal pattern. Push a bunch of marbles together and that's what you get. The bees don't know anything about hexagons. They just make circles close together and then as the cells are filled, stepped on, and come into contact with other wax cells, they "ballon out" into…
In particular, bees probably make hexagons because that minimizes the amount of wall you need per area, for a given cell size. If bees were really just making something like a voronoi diagram from somewhat spread out points, you wouldn’t get quite so regular a hexagonal tiling.
I imagine there’s some research about the precise method by which bees build their honeycombs, if anyone wants to go dive into the literature.