According to art. 5 of RD 557/2011, those non EU citizens who wants to enter Spain from a country outside Schengen area, while applying fot extension of his residence permit or applying for the new ID card for foreigners (TIE), will need to apply for a return permit.
The return permit will issued by the National Police Stations, you will need to apply for an appointment at this web site.
For more information see:
www.mpt.gob.es - Form EX_13
Return permit - Official Information Sheet (in Spanish)