The original ancestor of Y was the Semitic letter Waw, which was also the ultimate origin of the modern letters F, U, V, and W. See F for details.
In Ancient Greek, Υψιλον (Upsilon) represented IPA: , then later on /y/ — close front rounded vowel. The Romans had already borrowed this as the letter V, to represent both the vowel /u/ as well as the consonant /w/, but in later times, because the pronunciation of Ypsilon in Greek had shifted to /y/, they borrowed it directly in its original form, stem and all, as Y — mainly to represent names and words taken from Greek.
The letter Y was used in Old English, as in Latin, to represent /y/; however, some claim that this use was an independent invention in England created by stacking a V and an I, in other cases a type-setters' substitution for an old runic letter Yogh; both are unrelated to the Latin use of the letter. Regardless, it is fairly likely that the letter, although technically named Y Græca (IPA ) meaning ‘Greek u’ in contradistinction from native Latin /u/, came to be analyzed as the letter V (called /uː/) atop the letter I (called /iː/). The letter was thus referred to as [uː iː], which after /uː/ became the glide /w/ and after English's Great Vowel Shift naturally became /waɪ/.
By Middle English, /y/ had lost its roundedness and merged with /i/, and Y came to be used with the same values as I, /iː/ and /ɪ/ as well as /j/. Those dialects that retained /y/ spelled it with U, under French influence.
The Modern English use of Y is a direct continuation of this Middle English use. Thus the words myth [of Greek origin] and gift [of Old English origin], which originally contained high front rounded vowels, both have [ɪ].
With the introduction of printing, the letter Y was used by Caxton and other printers in England to represent the letter thorn (Þ, þ) which was lacking from continental typefaces, resulting in the use of ye for the word the.