1. Because most of northern africa was scrub, unsuitable for farming, with a hostile populace.
2. Because The original spanish goal was to seize ports to prevent/reduce slave taking raids on spanish territory, not conquer/settle africa.
It later expanded into a half arsed attempt to begin conquering the med, but they never really seemed to decide whether the goal was to conquer and hold territory, or just deny ports to the Ottomans to help secure spanish holdings on the isles/italian peninsula.