First a little bit of history: Swiss neutrality was first declared in 1516 after suffering a decisive defeat at the hands of king Francis I of France the previous year at Marignano, in northern Italy.
From then on the Swiss Confederation agreedto a perpetual peace with France, starting the principle of neutrality. In the centuries after the split between Protestants and Catholics inside the country made it impossible to decide which party to support in the religious wars, so Switzerland remained neutral even there and by that point the idea of neutrality started to become a guiding principle of the state, as proven by the decision in 1647 to create a common army for the preservation of neutrality and the declaration of independence in 1648.
Swiss neutrality was broken in 1798 with the french invasion of switzerland and the creation of an allied puppet state that lasted for the whole napoleonic period. After the congress of Vienna modern switzerland was born and the treaty affirmed the inciolability of swiss territory and its neutrality.
In 1907 the Aja convention declared the rights and duties of neutral countries and switzerland became one of them, alternating between partial neutrality (such as when it joined the society of nations and agreed to partecipate in economic sanctions) and complete neutrality (from 1938 to 2002 when it joined the UN).
So what are the reasons switzerland maintained neutrality so well: