The letter Y rarely gives us a consonant sound in the middle of a word. Instead it will usually be a long or short I sound. Occasionally Y will appear as part of a double letter vowel. However there is no spelling pattern that will tell us if the sound is long or short. (I have tried very hard to find one.) Even words with the same root will produce different sounds for Y. For example cycle / bicycle, type / typical.
The best I can find is that certain suffixes have a consistent sound. The suffix -YSM always has a short I as in abysmal, aneurysm and cataclysm. The suffix -YST has a short I (sometimes slurred to a schwa sound) as in amethyst, analyst, catalyst, cyst and tryst.
In Old English and Middle English the letters I and Y alternated in spelling, for example: bride / bryd, crystal / cristal, king / cyning and royal / roial; only one form survived into Modern English. Over time the letter Y was favoured for the end of words and the letter I in the middle. Y was not used for a vowel at the beginning of a word.
Common root words that kept Y, as a vowel, in the middle, are usually of Latin origin. Examples include: analysis (Medieval Latin -same spelling), physical (Medieval Latin physicalis), system (Late Latin systema) and type (Latin typus). Exceptions include, the word style (Old French stile), eye (from Old English ege) and nylon (a 20th century American new word).
Rarely the letter Y gives us a consonant sound in the middle of a word, as in beyond (Old English), canyon (Mexican-Spanish) and lawyer (Anglo-French). The word beyond is the Old English prefix be- and the root word yond. The now-obsolete root word is also found in words such as yonder. The word lawyer is from the Old English word law and the French suffix -ier. The -yer spelling is an English spelling of -ier (also found in old trades/family names like Sawyer and Bowyer). Words with an internal Y-consonant tend to have unusual histories.
In conclusion, the letter Y is both pronounced as a vowel and a consonant. Usually at the beginning of a word it is a consonant. It has no vowel sound of its own, but at the end of the word or in the middle it is used to represent other vowels. When you find Y in the middle of a word guess the pronunciation (short or long I) if you are unable to look it up.