1520s, "period of 40 days in which a widow has the right to remain in her dead husband's house." Earlier quarentyne (15c.), "desert in which Christ fasted for 40 days," from Latin quadraginta "forty," related to quattuor "four" (see four).
Sense of "period a ship suspected of carrying disease is kept in isolation" is 1660s, from Italian quarantina giorni, literally "space of forty days," from quaranta "forty," from Latin quadraginta. So called from the Venetian custom of keeping ships from plague-stricken countries waiting off its port for 40 days (first enforced 1377) to assure that no latent cases were aboard. The extended sense of "any period of forced isolation" is from 1670s.