You have asked a good question but one that does not have a very straightforward answer. For one thing, there is much acceptable variation among the three most common spellings of word-final long <e>: <y>, <ie>, <ey>. Cookie can also be spelled cooky and according to the Oxford English Dictionary, even cookey. Cabby can be spelled cabbie. Bony can be boney. Pixy can be pixie. Hoagie can be hoagy. And so it goes.
Beyond that, many such words that have only one correct spelling today had more than one in the past: For instance, today’s monkey was earlier spelled, among other ways, monkaie, munckey, munkai, monchy, munckie, munkye, munky, monkie. Today’s attorney was earlier spelled attorny and atturnie. Prairie, though a fairly recent adoption, has had several earlier spellings, including praire, prary, praari, prararee, prare.
But a few generalizations are in order: (i) The basic form is <y>, from Old English -ig, in which <g> was pronounced [y]. Thus Old English manig becomes our many. The <ie> spelling often is from French, though it has come to be used to form informal or diminutive words, like birdie, dearie, Jeanie, cabbie, etc. The <ey> spelling is used to form adjectives out of singular nouns that end with <y>, as in clayey and skyey.
Beyond that there does not appear to be much to be said.