This will depend on a number of factors but mainly be determined by your residency status. If you live in Spain but work in Gibraltar and pay taxes in Spain, you could well be treated as a Spanish resident, particularly if you can provide two years of Spanish tax returns.
If you are applying for a mortgage with a second applicant their residency status will also be taken into account. For example, if a joint application is from two people working in Gibraltar but both declare in Spain then a Spanish resident's mortgage could be granted. If one is declared solely in Gibraltar and the other in Spain then usually a non-resident’s mortgage will only be offered. In all cases, the property will need to be in Spain.