The OED has cites from 1483; for the first four hundred years or so, the word always referred to a place for sleeping.
There’s an interesting transitional use from 1858 recorded: “The dormitory was a large chamber divided into about a dozen cubicles, or small sleeping apartments, by wooden partitions and doors which rose within a few feet of the ceiling.” This introduces the idea of the cubicle as part of a larger space, sectioned off with something-that-is-less-than-a-wall, while retaining the sense of a space for sleeping.
Then, from 1926, we have “Seminars, cubicles, and private studies will be provided for…advanced students, and visiting scholars” (from an article in the Bulletin of the American Library Association). The cubicles here do not appear to be places for sleeping.
The etymology of “cubby”, according to the OED, is uncertain, but it’s thought to be connected to words from various Germanic languages meaning a stock-pen, a lean-to shed for cattle, a crib, chest or bin for fodder or a fish-trap on a weir.