Due to spains geographical position, it seems like a extremely precious location for both axis and allied forces during the war. Why did they remain neutral and not get invaded by either of the forces during WW2?
In 1939, Spain had just concluded an incredibly vicious three-year civil war which devastated the country and resulted in hundreds of thousands of deaths. The Franco regime was still young at the outbreak of war, and preoccupied with consolidating power, purging republican dissidents and re-establishing Spain's economy and civil society.
There were negotiations between Germany and Spain about Spanish entry into the war on the Axis side, but they finally broke down after Hitler and Franco failed to agree terms for Spanish intervention at a meeting at Hendaye in October 1940.
At Hendaye, Hitler deemed unreasonable Franco's demands for money, arms and large swathes of French territory in Africa, and was unwilling to compromise his relationship with the then-useful Vichy government in France. Franco opportunistically hoped to enter the war for as brief a period as possible, to reap the spoils without entangling Spain into another protracted conflict.
The relationship between Francoist Spain, Nazi Germany and Fascist Italy wasn't especially close; it was, at most, a marriage of convenience between three states with only broadly similar political outlooks — but whose leaders all mistrusted or essentially disliked one another. So, the failure to find mutually beneficial terms for Spanish entry into the war led Spain to remain non-belligerent.
That's also the key reason that Spain was never invaded: both sides had other strategic priorities, and there was no particularly compelling strategic reason to bring Spain into the war if they were content to sit it out.
Spain was, however, a key battleground in the intelligence war: as a neutral power in mainland Europe, bordering France and in close proximity to the Mediterranean and North African theatres, it was a pivotal region.
Franco's pro-Axis sympathies led his regime to allow the German intelligence services almost unfettered freedom to operate there. The Germans and Spanish collaborated, for example, on repeated (and mostly unsuccessful) attempts to sabotage British military facilities at Gibraltar.
On the other side, Allied intelligence was also well aware of Spain's utility as a covert entry-point into occupied Europe and as a valuable source of economic and military intelligence. Later, Operation Mincemeat, the British disinformation operation that enabled the Allies to catch German and Italian forces off-guard during the invasion of Sicily in 1943, took place on the coast of Andalusia.
In Britain, meanwhile, arguably the most valuable MI5 agent of the entire war was a Spanish diplomat named Juan Pujol Garcia (codename GARBO), who became a double agent and was pivotal in the Double-Cross System that hamstrung German intelligence operations in the UK.
You don't hear all that much because Spain didn't really participate in WW2 (Minus Azul Division, visa/passports for people escaping the Nazis*, etc) I may be mistaken, and it could just be they smuggled them through Spain and into Gibraltar
The geographical location doesn't matter so much when the Allies have Gibraltar or the North African coast. Even the invasions of France (Via Operations Overlord and Dragoon) were well away from France-Spain border, not to mention the difficulty of attacking through or around the Pyrenees.
As for neutrality, Franco didn't feel like he was required to help Hitler at all. And as for invading Spain, well - Hitler would've gained nothing by attacking, and the same could be said for the Allies.
Despite Franco's fascist leanings -- aside from his own domestic policies and eponymously-named ideology, his Nationalists received lots of materiel and manpower from the Germans and Italians during the Civil War -- Spain was in absolutely no position to fight. She was still recovering from the crippling three-year Civil War which ended with the total numer of dead at over 500,000, with an equal number fleeing as refugees from the authoritarian government's new rule. Franco's government was still dealing with quelling the final vestiges of internal political (and even military) dissent to his rule by the end of the Second World War in 1945. Though he perhaps could've made gains in the invasion of France (taking French Catalonia; though I doubt Franco would've caused himself the trouble, seeing as how he was trying to decimate the Catalan language), the Spanish Army and Navy would've been at the mercy of the Allied military, even before the US joined. The RN was strong enough itself to have enforced a blockade of Spain, and the RAF would have reduced what few industrial centers that survived the Civil War to literal rubble.
That is not to say, however, that Franco was completely neutral. In May 1941, after the sinking of the battleship Bismarck, the Spanish heavy cruiser Canarias and other Spanish ships took part in the search for surviving German sailors. Furthermore, perhaps more notably, the famous "Blue Division" (División Azul) was a Spanish volunteer infantry division that served as a part of the German Army on the Eastern Front, and became renowned for its exploits there.