All of this started in the age of exploration, this term wasn’t around until that time. The objective of this was to stop the spread of diseases, at that time navigation was very popular to explore new lands, transport people in to the new world etc… The crew and the cargo were forced to be quarantined for 40 days, to avoid the introduction of new disease or bringing back diseases. The 40 day comes from the origin of the word, which in french Quarante means 40, it is also used in the Bible.
The word quarantine might also be associated to the Italian word quarantena, which also means a 40 day period. It is also mentioned in the 13 chapter of the new testament of the Bible.