If Morocco is just across from Spain, why would Spain pay for the energy (i.e. cost of production, plus payoff of initial outlay, plus transportation, plus the company profits) rather than just build their own?
Firstly, Spain does have their own; one of their chief exports is renewable power into Europe. What Spain will probably do is take advantage of it's proximity to Morocco to establish a connection into their power grid for cheap. From there, let's say that Spain sells power to its own people for say 10 cents a KWH (completely made up figures) and it can buy power from Morocco for 8 cents a KWH (even if it's only during peak usage to keep their own equipment running at a higher efficiency) and sell to the rest of Europe for 12 cents a KWH, then it makes sense to buy from Morocco and increase their supply. With roughly 1/10th the per capita GDP of Spain and a similar GINI index rating, Morocco has an economic advantage over Spain in the labor market so it isn't hard to imagine that they can produce the same amount of power cheaper. Also, the only realistic route to sell power to Europe from Morocco will need to go through Spain, so if they wanted to be complete dicks about it Spain could leverage that in negotiations as well. Add into account any existing contracts\treaties that the other European countries have with Spain to buy power and it starts to look like the only outcome that makes any sense.