This is often asked, and he general consensus:
Switzerland is extremely mountainous, and in the case of WW2 was fortified with collapsible tunnels and dynamite-rigged roads, hidden artillery, and after WW2 aircraft caverns and advanced layered defenses. The Swiss made adequate preparations and provisions and they had/have mandatory military service for all male citizens and good training.
Switzerland is not a significant strategic or tactical location, and had no real resources or industry to make it worth an invasion.
Switzerland was easier to manipulate and coerce diplomatically. Plenty of Swiss fought for both the Axis and Allied sides, directly as mercenaries and volunteers, financially, commercially, a hub for espionage and refugee asylum, overall a very dynamic player in WW2 and other international concerns despite their 'neutrality'.
The Germans indeed laid out detailed plans to invade Switzerland, Operation Tannenbaum, and the invasion likely would have been victorious if not protracted. The Eastern Front and later the invasion at Normandy diverted and then cancelled Nazi plans of invading.
Related/Similar posts
https://www.reddit.com/r/AskHistorians/comments/y7a0b/why_did_hitler_never_invade_switzerland_or/