Minerals form from solutions, melts and vapors.
When as substances is in liquid or gaseous form the atoms are randomly arranged with no internal structure. What is happening internally when the substance changes phase from liquid or gas to solid is the atoms are becoming more and more organized and structured. This phase change can be precipitated by changes in the surrounding environment. The easiest way to form a crystal is by evaporation of water. There is a limit to the number of atoms that can be contained by a volume of water.