"frame with bars," c. 1300, possibly from Middle Dutch rec "framework," literally "something stretched out, related to recken (modern rekken) "stretch out," cognate with Old English reccan "to stretch out," from Proto-Germanic *rak- (source also of Old Saxon rekkian, Old Frisian reza, Old Norse rekja, Old High German recchen, German recken, Gothic uf-rakjan "to stretch out"), from PIE root *reg- "to move in a straight line" (from PIE root *reg- "move in a straight line").
Meaning "instrument of torture" first recorded early 15c., perhaps from German rackbank, originally an implement for stretching leather, etc. Mechanical meaning "toothed bar" is from 1797 (see pinion). Meaning "set of antlers" is first attested 1945, American English; hence slang sense of "a woman's breasts" (especially if large), by 1991. Meaning "framework for displaying clothes" is from 1948; hence off the rack (1951) of clothing, as opposed to tailored.