The answer is lattice energy.
The enthalpies involved in the formation of ionic compounds can be understood by Born-Haber cycle.
The following steps are involved in the formation of $\ce{NaCl}$ for example.
$$\ce {Na(s) -> Na(g)}\tag{1}$$
$$\ce{Na(g) -> Na+ + e-}\tag{2}$$
$$\ce{1/2 Cl2(g) -> Cl(g)}\tag{3}$$
$$\ce{Cl(g) + e- -> Cl^{-}(g)}\tag{4}$$
$$\ce{Na+(g) +Cl^{-}(g) -> NaCl(s)}\tag{5}$$
You can see that energy is required in the steps 1-3 whereas energy is evolved in 4th and 5th steps.
The energy evolved in the 5th step is called the lattice energy of the ionic compound and this only is responsible for the overall process being exothermic.
Now why lattice formation is exothermic? This is because when a lattice is formed, new attractive forces are set up that are dominant over the new repulsive forces set up. As it is known that attractive forces decrease the potential energy of a system(or increase the stability), so energy is released as heat.