This prayer is called the Sanctus because that is its first word in Latin. The first line is the hymn of the seraphim in Isaiah 6:3 and Revelation 4:8. The second part is what the crowd cried to Jesus at his triumphal entry into Jerusalem (Mt 21:9), which is modeled after Psalm 118:25.
Hosanna is a Hebrew term which is derived from the words yasha, which means "save," and na, which is an expression of entreaty or request and can be translated in a variety of ways-for example, "I pray," "I beseech," "please," or "O." The Hebrew terms were combined - yasha na ("O, save!"), as in Psalm 118:25 - and this became hosanna.
It was used as part of the Jewish temple liturgy during the feast of Tabernacles, when the priests carried willow branches and cried "Hosanna!" while processing around the altar of burnt offering'. Over time, the crowd gathered to worship picked it up, and it became a cry of joy. The seventh day of Tabernacles even came to be called "Hosanna Day."
Thus the crowd greeted the Messiah by waving palm branches and joyfully crying "Hosanna!" to him as he entered Jerusalem. By this time, the term may have lost some of its original meaning and may have been mostly an acclamation of joy and petition (as it is now during Mass).
Yet it still carried the air of a joyful petition for deliverance The expression "Hosanna to the Son of David!" was an exhortation to acclaim or praise the Messiah in hopes of deliverance (probably from the hated Romans in the mind of the crowd).
The expression "Hosanna in the highest!" is more mysterious. Suggestions have included the idea that it is an exhortation to us to cry "Hosanna!" to God, that it is an exhortation to the angels to cry "Hosanna!" to God, that it is an exhortation for there to be songs of praise in heaven, and even that the phrase means "Up with your branches!" (on the unlikely supposition that the branches carried during the feast of Tabernacles had come to be called "hosannas").
"Hosanna" was used as part of Mass in the first century. The Didache (A.D. 70) includes the acclamation "Hosanna to the God of David!" among the congregation's responses during the prayer of thanksgiving after Communion.