In 431 the Council of Ephesus formally bestowed on title of Mother of God. This was to settle a controversy of two lines of thought about Mary's role as bearer of Christ. There were two schools of thought about this by two prominent theologians at the time. The first one was by Nestorius who advocated that Mary should be referred to as mother of Christ(Christotokos) not mother of God (Theotokos) , being that Mary was a creature created by God she could not be the Mother of God. On the other side of the argument was Cyril of Alexandria, who claimed that Mary was bearer of all of Christ not just his humanity. He said we cannot separate the divinity from the humanity of the baby in the womb so if Mary is bearing the Jesus she is bearing both natures of him divine and human. So the Church officially proclaimed the doctrine of Theotokos or loosely translated Mother of God.
That is the matter in a nutshell of how the title came to be, it was much more involved and there was much debate leading up to and following the proclamation by the council.
There is also scriptural backing for this title, immediately before mary gives The Magnificat Elizabeth greets her by this title.
“When Elizabeth heard Mary’s greeting, the baby leaped in her womb; and Elizabeth was filled with the Holy Spirit. And she cried out with a loud voice and said, “Blessed are you among women, and blessed is the fruit of your womb! “And how has it happened to me, that the mother of my Lord would come to me? “For behold, when the sound of your greeting reached my ears, the baby leaped in my womb for joy. “And blessed is she who believed that there would be a fulfillment of what had been spoken to her by the Lord.” Luke 1:41-45
So we celebrate the feast of Mary the Mother of God which the church debated and settled in 431 at the council of Ephesus.
For a great scholarly book about this topic check out this book by John McGuckin.