It’s ultimately from the sense of “make a rope fast to a spar,” but the phrase is a bit more interesting.
The proximate origin is the name of a con game, along the lines of three-card monte (in spirit, not in actual structure of the game). From George Whetstone’s 1578 The Right Excellent Historye of Promos and Cassandra:
At fast or loose, with my Giptian, I meane to haue a cast.
The game is undoubtedly somewhat older than this, as the metaphorical sense predates this citation by some decades. From Tottel’s Miscellany of 1557:
Of a new maried studient that plaied fast or loose.
The game is described in this quote from James O. Halliwell’s 1847 A Dictionary of Archaic and Provincial Words, Obsolete Phrases, Proverbs and Ancient Customs, from the Fourteenth Century:
Fast-and-loose, a cheating game played with a stick and a belt or string, so arranged that a spectator would think he could make the latter fast by placing a stick through its intricate folds, whereas the operator could detach it at once.