If you're planning to visit southern Spain, Morocco is an easy add-on and well worth the detour. At a minimum, do a Tangier day trip and return to Spain the same evening. But I recommend staying at least one night so you can visit Chefchaouen or take more time to explore Tangier.