It’s not considered a molecule as a molecule is considered to be a group of atoms bonded together sharing electrons (covalent bond). Sodium chloride is not covalently bonded and shares no electrons, thus not a molecule. Instead it is an ionic bonded meaning electrons are transferred, in this case it’s the sodium loses or gives an electron to the chlorine, the easiest way to explain it is, if you think of it as sodium has one electron in its outer shell, where as chlorine has 7, both these atoms want to complete their outer shell, but it’s easier for the sodium to give up it's one than for chlorine to give up 7. This causes sodium to form a Na+1 ion (cation as its metal, note hydrogen is an exception to this as it can form cations and anions but that's a whole different matter) and chlorine becomes Cl-1 ion (anion as its non-metal). Strong electrostatic forces between these two ions then hold them together as the positive and negative ions are attracted to each other.