A substance should contain charged particles that are free to move around in order to conduct electricity.
Ionic compounds contain an ocean of ions. They carry either positive or negative charges. Attractions between them hold them in a rigid lattice under the solid state. Those ions are unable to move. The ionic compound can't conduct electricity.
Melting the ionic compound will break the lattice. Those ions are now free to move to conduct electricity. Dissolving the compound in water will also free the ions. As a result, those solutions will also conduct electricity.
Conductivity under different states distinguishes between ionic compounds, molecular compounds, and metals.