The origins of pike and shot as a battle formation is generally credited to the late-15th century Spanish, particularly an army re-organization undertaken by Gonzalo Fernández de Córdoba. Facing the professional military of the French cavalry and Swiss mercenary infantry, he integrated arquebusiers into the fighting formation.
The basic idea is that the arequebusiers provided offensive power, and the pikemen protected the shooters from cavalry charges. It was not, at first, a rigid formation - the shooters would simply run behind the pike line when threatened.
The idea proved sound, especially at the Battle of Cerignola, where the Spanish held their ground against the French army despite being heavily outnumbered.
Pike and shot faded out of relevance with the introduction and refinement of the bayonet, which allowed a long musket to be braced as a spear against cavalry, as well as the general increase in power and accuracy of gunpowder weapons. By around 1700 the pike had pretty much fallen out of use in most European armies.