It might have to do with the fact that the arrivals country is different from the departure country for the return flight and Marocco is belonging to the geogarphical area of Africa and Madrid obviously to Europe.
Probably best to talk to a qualified travel agent about such a special case as they can see all the rules and options which any online tool (let alone the IB website) will not be able to display and consider.
Could also work if you buy the segment MAD-CAS seperately which can however result in an issue if you are planning an immediate transfer in Madrid and no stopover. Technically you first trip would end in Spain and you would porbably have to go through immigartion before checking-in for the onward leg.