So the invasion of Spain could only happen if they are willing to delay Barbarossa, meaning they would start knowing they wouldn't reach Moscow till 1942 at least, and would have to fight General Winter before the war against the USSR was over. An invasion of Spain after Barbarossa would be... too stupid for words (well, i think

).
The biggest reason the Germans would have to invade a republican Spain would be to deny the allies a western front. Nevertheless, the Pyrenees can do that pretty effectively as well: it works both ways. Why invade Spain to avoid being invaded from there, when you can set up a defensive barrier that can be easily made impenetrable with a small fraction of the cost?
*I think this is important because it's the only reason that would push them to make a hilarious decision early on.