Why does crystalline solids have well defined 3d geometry
Keep two concepts separate: the solid crystalline state is not bound to occur on ionic compounds only.

In a simple view, crystalline describes a regular arrangement of matter, with predictable order both in short, as well in long range.  For the crystalline state, it is unimportant if the constituents of the crystal are atoms (like metal atoms), charged particles (like your example of NaCl), or neutral molecules (like benzoic acid) or even a mixture of neutral and charged molecules (many protein crystals contain water).

Some materials are easier packed in such a regular pattern, than others.  In the instance of metals, their (on first approximation) sphere like atomic geometry and similar radius eases such a settlement.  Inorganic salts tend to be a bit more complicated, as often smaller ions are localized in gaps built by larger ions (octahedral / tetrahedral gaps).

Organic molecules may equally build crystals, yet their shape and conformational flexibility around single bonds (for example in alkyl chains) and multiple intermolecular interactions may keep them over a long time in a glassy state (like supercooled benzoic acid, or some brands of honey).  More than for the aforementioned examples: formation of a nice crystal may be thermodynamically favourable, but it is not enough "just to cool down" below the melting temperature to reach this energetic minimum.  There must be seeds of crystallization, and typical conditions of their formation (temperature, concentration, etc.) are not necessarily the same where nicely shaped crystals growth further.

It is not surprising crystals attract attention, for example in material science and crystallography, and that there are journals with focus on the relationship between molecular properties, and macroscopic / crystallographic ones; like CrystEngComm or Crystal Growth &amp; Design.