The sheep economy was forced upon Scotland by the British during the Highland Clearances [1] which followed the subjugation of the Highlands after the failed Jacobite Rebellion.
Peasants who were not involved in sheep farming were forcibly evicted or killed, resulting in the sheep-centric agriculture we see today, and also triggered the earliest large Scottish peasant migrations to the Americas.
According to the guides at the Battlefield of Culloden, prior to the Clearances, the Scottish Highlands had a more mixed agricultural and cottage industrial economy, but basically got turned into a sheep production "banana republic" after the British defeated them.
5.8 million people, 13.5 million pigs