Well, being the continent's money vault and avoiding two world wars while the whole continent ravaged itself twice, tends to make a huge difference in your nation's development (time in the market beats timing the market and Switzerland did both).
Also, just like the USA, Switzerland won the geopolitical lottery early on by being in a position that's easy to defend and difficult to attack and capitalized on it over the decades by attracting the highly educated elite and the wealthy entrepreneurs escaping from the European countries as they were torn by wars and revolutions, plus the dirty money of warlords, dictators and criminals from all over the world made them incredibly prosperous. It's not a repeatable formula that any other EU country could have easily replicated.
Adding the fact that Switzerland is incredibly restrictive with who they accept in the country, compared to neighboring EU countries who just let the dross in to virtue signal how tolerant they are, maintains Switzerland a very safe and desirable place to be despite it being relatively diverse (diversity in this context also means diversity of thought and diversity of opinion, not just the US identity politics version of only meaning non straight white males). So another win for them.
But if you look at Swiss elections, plenty of candidates took the xenophobic route in their campaigns demonizing Muslims and burkas as the biggest threat, but unlike EU members they don't really care what other think of them so they're a lot more outspoken about it.[1][2]
[1] https://www.dw.com/en/anti-minaret-campaign-divides-switzerl...
Just one nitpick - people love bashing swiss banking and relation to money laundering and nazis. If you check the numbers, this had absolutely minimal effect on economy, even now banks together form cca 10% of the economy, tourism has bigger impact. Plus its a profit kept within corporations who dont pay massive taxes back to state, so there are some benefits but its overblown, but makes easy blaming mental shortcut. Emotions emotions...
And I stand by the fact most of swiss success could be easily repeated in ie Germany or France, they have the competence, if they were setup differently and folks had slightly different mindset. Its no magic, just few extra rules and responsibilities. But no they have to have overblown easy to abuse social state, high taxes. Of course this doesnt work well. Again swiss have by far the best and most sustainable/resilient model in this, good health and social systems, yet low taxes and state basically doesnt have deficits