mid-15c., detencioun, "act of keeping back or withholding," from Old French détention (13c.) and directly from Late Latin detentionem (nominative detentio), noun of action from past-participle stem of Latin detinere "hold back, keep off" (see detain).
Sense of "confinement, restraint, state of being detained" is by 1570s (in reference to Mary Queen of Scots). In reference to "a keeping in" as a school punishment, from 1857.