Ions bound together by electrostatic attraction form ionic crystals.
Stability of ionic solids depends on lattice energy, which us released in the form of heat when two ions are brought together to form a solid. Lattice energy is the sum of all the interactions within the crystal.