The dynamic crystallization of cubic granular particles under three-dimensional mechanical vibration is numerically investigated by the discrete element method. The effects of operational conditions (vibration, container shape and system size) and particle properties (gravity and friction) on the formation of crystals and defects are discussed. The results show that the formation and growth of clusters with face-to-face aligned cubic particles can be easily realized under vibrations. Especially, a single crystal with both translational and orientational ordering can be reproduced in a rectangular container under appropriate vibrations. It is also found that the gravitational effect is beneficial for the ordering of a packing; the ordering of frictional particles can be improved significantly with an enlarged gravitational acceleration. The flat walls of a rectangular container facilitate the formation of orderly layered structures. The curved walls of a cylindrical container contribute to the formation of ring-like structures, whereas they also cause distortions and defects in the packing centers. Finally, it is shown that the crystallization of inelastic particles is basically accomplished by the pursuit of a better mechanical stability of the system, with decreasing kinetic and potential energies.