Until the end of 2018, if during the Spanish nationality application procedure you lost your residency status (maybe because you didn’t renew your current permit); your application could get rejected.
Nevertheless, after the beginning of 2019 that changed.
Now it won’t be a problem. If you meet all the requirements that can grant you Spanish citizenship, you can lose your resident status and still get the nationality.