late 14c., "continue keeping of, keep possession of, keep attached to one's person;" early 15c., "hold back, restrain" (a sense now obsolete); from Old French retenir "keep, retain; take into feudal service; hold back; remember" (12c.), from Latin retinere "hold back, keep back, detain, restrain," from re- "back" (see re-) + tenere "to hold" (from PIE root *ten- "to stretch").
The meaning "to engage to keep (another) attached to one's person, keep in service" is from mid-15c.; specifically of lawyers from 1540s. Meaning "keep in the mind, preserve knowledge or an idea of" is from c. 1500. Related: Retained; retaining.