You are quite correct that the enthalpy change to form an isolated Na$^+$ and an isolated Cl$^-$ ion from gaseous Na and Cl atoms is positive. However you need to include the very large and negative enthalpy change when the ions come together to form solid NaCl. A quick Google found this energy diagram:
To calculate the enthalpy of formation of NaCl from solid sodium and gaseous chlorine you need to sum the energies for all the steps. If you do this you find the overall enthalpy change is negtive and that's why NaCl is formed.