Here’s one example, this mechanism doesn’t apply to all minerals/elements:
Gold is a heavy element that, for the most part, is non-reactive under near surface conditions (it doesn’t form compounds with other elements).
Under extreme conditions (high pressure and temperature) such as those found in the deep crust, gold can react with sulfur to form a complex compound that happens to be soluble in water. Typically this compound will be diffused through deep rocks at extremely low concentrations.
Imagine now a huge magma plume, a roughly spherically-shaped blob a few thousand meters across and 20+ km below the surface. When it cools, mineral crystals begin to form. Most likely it will cool from the outside in, isolating the molten material inside a gradually thickening layer of solid, non-porous rock (say granite).
Water, for the most part, is not included in the crystal lattices of most minerals – it is expelled from the newly formed crystals and remains associated with the molten material inside the plume. As crystallization proceeds and the space shrinks, the remaining water is subjected to higher and higher pressures. If the gold-sulfur complex is present it will easily be dissolved in the fluid (which will also dissolve other, more common compounds like silica – SiO[sub]2[/sub]).
At some point late in the process, fractures form in the crystallized portion of the chamber (due to shrinkage, internal pressure, etc.). At this point the high pressure fluids will be ejected at extremely high velocities. As pressure drops two things happen: (1) at lower pressure but still high temperatures the water will flash to vapor, reducing its viscosity and allowing it to escape through much smaller fractures and pore; (2) at lower pressures the gold separates from the sulfur and recombines to form elemental (metallic) gold. While this happens the other minerals dissolved in the hot fluid will also crystallize rapidly, filling the fractures with (mostly) a fine-grained, milky quartz. Included in this quartz vein will be flakes, nuggets or crystals of relatively pure gold.
If/when these newly formed rocks are uplifted to the surface these gold-bearing quartz veins will be carried with them, gradually weathering and eroding at the surface and leaving the gold residue to be carried downhill to the nearest stream and be distributed among the heavy sediments on the stream bed (this is called a placer deposit).