Origins
Open a thesaurus and you are opening a treasure chest. The two words are the same. Both descend from Greek thēsaurós, meaning 'a store' or 'a hoard' — things laid up for safekeeping.
The Greek word entered Latin as thēsaurus, meaning both the wealth stored and the vault that held it. Old French compressed the sound to tresor, and Middle English received it as treasure around the 12th century.
The scholarly Latin form survived separately. When Peter Mark Roget published his famous reference work in 1852, he called it a Thesaurus — a treasury of words, synonyms hoarded and catalogued like gold coins in a vault.
French Influence
English split the word's functions. Treasure is the wealth. Treasury is the building. Treasurer is the person who guards it. The British Exchequer (from Old French eschequier, a chequered counting board) serves the same role but with a different etymology.
The Greek thēsaurós may derive from a root meaning 'to put' or 'to place' — a treasure is fundamentally something placed somewhere for safekeeping. This is why treasure implies hiddenness. Gold on a table is wealth. Gold buried in a chest is treasure. The act of storing transforms the material.
The verb 'to treasure' extends the metaphor inward. To treasure a memory is to store it carefully, guarded against loss — the same protective act, performed on something invisible.