Staying together in a tight formation and using lots of pointy things against cavalry weren't a new invention by the Swiss-I suspect it was discovered shortly after horses were first used in warfare. It's also quite effective against infantry, and not completely foolproof against cavalry either.
As always, cavalry were most effective when used as part of a combined arms system. For example, at Falkirk, the English men-at-arms swept their Scottish counterparts off the field. The longbowmen then shot the Scottish pikes to pieces with impunity, at which point the men-at-arms swept back in to finish the flagging scots. At Waterloo, French cavalry forced British units into square where they could then be hammered with artillery. At Marignano, French Gendarmes succeeded at throwing back Swiss attacks on the artillery, letting the artillery devastate the tightly packed Swiss formations.
Of course not, spear armed men on foot were there before men on horses. The important part probably is "staying together", which involved morale beyond most medieval footmen and next training and equipment aimed at countering heavy cavalry. The Swiss pikemen were not just polearmed, but used halberds with "hooks" to grab the knight's armour and drag them from their horses.
The co-operation of the various arms on the battlefield always has been decisive and in a tactical context this usually is executed as "fire and movement". When heavy cavalry reigned vs. ordinary footmen movement had the upper hand though, and when musketry became refined firepower gradually took over. Not without "bumps" however. By early 17th century heavy cavalry had been reduced to riding up close to the enemy formation and discharging pistols until Gustav Adolph reinvented the heavy cavalry charging with cold steel. These heavy and partially armoured cavalry units (Cuirassiers) were proud parts of most armies until late 19th century but at the moment I don't recall any successful use after the Napoleonic wars and even here only under very narrow conditions and with heavy losses (like Wagram).
The musket and later the Minie rifle and especially rifled artillery doomed cavalry as the "movement" instrument on the battlefield. Initially infantry in columns became the new "movement" supported by skirmisher and artillery fire and worked best where the charging infantry was well co-ordinated with (rifled) artillery. In a few decades Minie rifles were more widespread than rifled artillery and this really put everything upside down, as the infantry now could outrange the artillery!
The machinegun of course didn't make the "movement" part any more easy, but IMHO railways were more important in the final doom of cavalry and temporary doom of movement. Railways meant that the defender very fast could pour reinforcement and not at least artillery with huge loads of ammo in front of an enemy breakthrough but the attacker moved as slowly as in ancient times - even slower due to the terrain broken by shell craters, and couldn't bring much morer than they could carry.