From the old Catholic Encyclopedia;
The history of the devotion to the Heart of Mary is connected on many points with that to the Heart of Jesus; nevertheless, it has its own history which, although very simple, is not devoid of interest. The attention of Christians was early attracted by the love and virtues of the Heart of Mary. The Gospel itself invited this attention with exquisite discretion and delicacy. What was first excited was compassion for the Virgin Mother. It was, so to speak, at the foot of the Cross that the Christian heart first made the acquaintance of the Heart of Mary. Simeon's prophecy paved the way and furnished the devotion with one of its favourite formulae and most popular representations: the heart pierced with a sword. But Mary was not merely passive at the foot of the Cross; "she cooperated through charity", as St. Augustine says, "in the work of our redemption".
Another Scriptural passage to help in bringing out the devotion was the twice-repeated saying of St. Luke, that Mary kept all the sayings and doings of Jesus in her heart, that there she might ponder over them and live by them. A few of the Virgin's sayings, also recorded in the Gospel, particularly the Magnificat, disclose new features in Marian psychology. Some of the Fathers also throw light upon the psychology of the Virgin, for instance, St. Ambrose, when in his commentary on St. Luke he holds Mary up as the ideal of virginity, and St. Ephrem, when he so poetically sings of the coming of the Magi and the welcome accorded them by the humble Mother. Little by little, in consequence of the application of the Canticle of the loving relations between God and the Blessed Virgin, the Heart of Mary came to be for the Christian Church the Heart of the Spouse of the Canticles as well as the Heart of the Virgin Mother. Some passages from other Sapiential Books, likewise understood as referring to Mary, in whom they personify wisdom and her gentle charms, strengthened this impression. Such are the texts in which wisdom is presented as the mother lofty love, of fear, of knowledge, and of holy hope. In the New Testament Elizabeth proclaims Mary blessed because she has believed the words of the angel; the Magnificat is an expression of her humility; and in answering the woman of the people, who in order to exalt the Son proclaimed the Mother blessed, did not Jesus himself say: "Blessed rather are they that hear the word of God and keep it", thus in a manner inviting us to seek in Mary that which had so endeared her to God and caused her to be selected as the Mother of Jesus? The Fathers understood His meaning, and found in these words a new reason for praising Mary. St. Leo says that through faith and love she conceived her Son spiritually, even before receiving Him into her womb, and St. Augustine tells us that she was more blessed in having borne Christ in her heart than in having conceived Him in the flesh.
It is only in the twelfth, or towards the end of the eleventh century, that slight indications of a regular devotion are perceived in a sermon by St. Bernard (De duodecim stellis), from which an extract has been taken by the Church and used in the Offices of the Compassion and of the Seven Dolours. Stronger evidences are discernible in the pious meditations on the Ave Maria and the Salve Regina, usually attributed either to St. Anselm of Lucca (d. 1080) or St. Bernard; and also in the large book "De laudibus B. Mariae Virginis" (Douai, 1625) by Richard de Saint-Laurent. Penitentiary of Rouen in the thirteenth century. In St. Mechtilde (d. 1298) and St. Gertrude (d. 1302) the devotion had two earnest adherents. A little earlier it had been included by St. Thomas Becket in the devotion to the joys and sorrows of Mary, by Blessed Hermann (d. 1245), one of the first spiritual children of St. Dominic, in his other devotions to Mary, and somewhat later it appeared in St. Bridget's "Book of Revelations". Tauler (d. 1361) beholds in Mary the model of a mystical, just as St. Ambrose perceived in her the model of a virginal soul. St. Bernardine of Siena (d. 1444) was more absorbed in the contemplation of the virginal heart, and it is from him that the Church has borrowed the lessons of the Second Nocturn for the feast of the Heart of Mary. St. Francis de Sales speaks of the perfections of this heart, the model of love for God, and dedicated to it his "Theotimus".