1550s, "regular geometric body with six square faces," also "product obtained by multiplying the square of a quantity by the quantity itself," from Middle French cube (13c.) and directly from Latin cubus, from Greek kybos "a six-sided die," used metaphorically of dice-like blocks of any sort, also "cake; piece of salted fish; vertebra," of uncertain origin. Beekes points out that "words for dice are often loans" and that "the Lydians claimed to have invented the game" of kybos.
The mathematical also was in the ancient Greek word: the Greeks threw with three dice; the highest possible roll was three sixes. The word was attested in English from late 14c. in Latin form. The 1960s slang sense of "extremely conventional person" (1959) is from the notion of a square squared. Cube-root is from 1550s (in Middle English this was simply a cubick).