If you're interested in this, you're going to want to read Cubed: A Secret History of the Workplace by Nikil Saval. It came out about a year ago, so you should be able to find a copy pretty cheap.
In brief, the cubicle as we know it today is a derivation of an idea by a designer named Robert Propst, who in 1958 started working for the Herman Miller Company. At the time, a lot of office design was focused on the open plan concept.
Ever see Mad Men? Think of the typing pool, with symmetrical rows of desks in the middle of a wide open office. In the late 1950s and early 1960s, psychologists, doctors and others were realizing that the open plan had some problems. Folks needed a personalized space to reach peak performance. The trick was to provide that space without closeting everyone into individual rooms, as had been the design before the open-plan office became popular.
In 1964, Propst came up with what he called the "Action Office," a modular collection of multiple components that could be moved around. There were standing desks with roll-tops that could be secured, meaning workers no longer had to clear their desks at the end of the day.
Action Office wasn't a big success, so Propst came up with a sequel, Action Office II, which in the mid-to-late 1960s more closely resembles the cubicle.
Changes in the U.S. federal tax code in the late 1960s made it easier for companies to write off depreciating assets, which meant it was suddenly "cheaper to have an Action Office than an actual office," Saval wrote.
One of the most famous early adopters of the cubicle was Intel, which liked the egalitarian nature of the cubicle. At its start, even the CEO of Intel was in a cubicle. Other companies, eager to ape Intel's style (much as we've seen with Google today), got cubicles of their own.
In the 1980s, however, there was a predatory emphasis on maximizing profit for shareholders. The cubicle became much less of an egalitarian symbol as office space shrank and cubicles became more tightly packed. Instead of becoming a symbol of freedom, the cubicle became a symbol of captivity.