To marry in Spain, whether in a civil service or a religious one, at least one of those being wed needs a 'certificado de empadronamiento', showing that he/she has been legally resident in Spain for two years.
If the other party to the marriage isn't legally resident in Spain, he/she will need a 'certificado de no impedimento', issued by the consular authorities in his/her home country, showing that there is no legal impediment to the marriage.