The adjective is from 1680s, "private, done in seclusion;" from 1782 as "fitted only for scholarly seclusion, not adopted to the conditions of practical life." The meaning "secret, not public, unknown" is recorded from 1952, first of alcoholism but by 1970s used principally of homosexuality; the phrase come out of the closet "admit something openly" is first recorded 1963, and lent a new meaning to the word out.

closet (v.)

"shut up as in a closet" (originally usually for purposes of concealment or private consultation), 1680s, from closet (n.). Related: Closeted; closeting. Closeted in the sense of "in private and confidential consultation" is from 1680s.