The captain of a ship flying the Spanish flag must be an EEA national.
"Article 9. Civil fleet and fixed platforms.
1. For the purposes of this law, the following is considered a Spanish civil fleet:
a) The national merchant fleet.
b) The national fishing fleet.
c) National recreational and sporting vessels.
d) The other Spanish civil vessels not included in the previous letters.
2. A civil vessel is understood to be any vessel, platform or floating device, with or without displacement, suitable for navigation and not used for the service of national defense.
3. A merchant ship is understood to be any civilian vessel used for navigation with a commercial purpose, excluding those engaged in fishing. [...]
5. This law shall apply to the Spanish civil fleet, as well as to fixed platforms located in waters in which Spain exercises sovereignty, sovereign rights or jurisdiction.
[...]
Article 253. Vessel endowments. [...]
2. The master and the first deck officer of national ships must have the nationality of a Member State of the European Economic Area, except in the cases in which it is established by the maritime Administration that these jobs must be carried out by citizens of nationality Spanish for implying the effective exercise in a regular way of public power prerogatives that do not represent a very small part of its activities. The rest of the crew, in the case of merchant ships, must be of Spanish nationality or of some other member state of the European Economic Area, at least 50 percent. [...]" (Royal Legislative Decree approving the Consolidated Text of the Law on State Ports and the Merchant Marine (2/2011, of September 5), last amended on 31 December 2020, Articles 9 and 253(2) [google translation])
Royal Legislative Decree approving the Consolidated Text of the Law on State Ports and the Merchant Marine (2/2011, of September 5), in force from 21 October 2011, Articles 9 and 253(2) 
[<a href="https://www.boe.es/buscar/act.php?id=BOE-A-2011-16467">Decree</a>]