The custom of the midnight mass comes from the Holy Land, namely from Jerusalem and Bethlehem, where around the wooden pieces of the holy manger until the IV. century, the birth of the savior was celebrated every year. When the remains of the manger were brought to Rome in the Santa Maria Maggiore church in the 500s, the custom of midnight mass was continued here as well.
This ceremony was actually the first Holy Mass on the Christmas holiday, so it is no wonder that the Christian Church later officially included it in its list of important ceremonies. Saint Gregory already mentions the midnight mass, which is the earliest event of the first day of Christmas, although at first they celebrated not only the birth of the savior, but also commemorated the virgin martyr Saint Anastasia, who was burned for her faith on December 25th. Incidentally, the song narrating the life of St. Anastasia still pops up in the second half of midnight masses. The virgin helped her fellow Christian prisoners with medicines and never consummated the marriage with her pagan husband, so finally the girl from a Roman patrician family was burned with 200 other virgins by Emperor Diocletian.
Many ecclesiastical and secular customs were connected to the midnight mass itself in the past centuries. One of the most important and most common, which we still know today, was the nativity scene: in this, enthusiastic amateurs went from house to house to act out the story of the birth of baby Jesus, together with the legend of the three kings and the appearance of the shepherds. This shepherd's play was finally in the XIX. at the end of the 20th century, it was relegated from the apartments and houses to the courtyards of the churches, and in many places it became a permanent program before mass. Since angels and shepherds were constant characters in these games, Christmas midnight mass is still called angelic or shepherd mass in many regions. The mass was usually started in the dark, without lighting, and the candles were lit in the church only when the baby Jesus was born in the shepherd's play, thus indicating that the savior who brings light has arrived.
Source: bpromanticaja