Uncovering grain-scale mechanisms that underlie the disorder–order transition in assemblies of dissipative, athermal particles is a fundamental problem with technological relevance. To date, the study of granular crystallization has mainly focussed on the symmetry of crystalline patterns while their emergence and growth from irregular clusters of grains remains largely unexplored. Here crystallization of three-dimensional packings of frictional spheres is studied at the grain-scale using X-ray tomography and persistent homology. The latter produces a map of the topological configurations of grains within static partially crystallized packings. Using numerical simulations, we show that similar maps are measured dynamically during the melting of a perfect crystal. This map encodes new information on the formation process of tetrahedral and octahedral pores, the building blocks of perfect crystals. Four key formation mechanisms of these pores reproduce the main changes of the map during crystallization and provide continuous deformation pathways representative of the crystallization dynamics.