I had heard this before so I did some looking around. It seems that the song The Twelve Days of Christmas may have either originated with or was used as a Catechism tool by Catholics during the period of religious persecution during and around the Enlightenment Age. I imagine this period of persecution may have had temporary pauses (such as during the tenure of James II) but the number of Catholic martyrs from England during these years attests to the severity of oppression that was going on. Here's what the author of the original article (Fr. Stockert) where the reference to the origin of The Twelve Days had to say about it:
"The Twelve Days of Christmas" was written in England as one of the "catechism songs" to help young Catholics learn the tenets of their faith - a memory aid, when to be caught with anything in *writing* indicating adherence to the Catholic faith could not only get you imprisoned, it could get you hanged, or shortened by a head ? or hanged, drawn and quartered...
Basically the song was an undercover "code" where each "gift" represented a spiritual "gift". You can also view the article from which this quote is from to see what the various "gifts" in the song represent ("Seven Swans a-Swimming" = seven sacraments/gifts of the Holy Spirit). So is this true? It looks like this hasn't been investigated enough to find out whether this is how the song truly originated. Even if the song didn't originate as a teaching aid, it has been said that the song could have been adopted by Catholics in England to act as a teaching aid. This would be an interesting research assignment to follow up on...
Christmas has been celebrated since the days of the early Christians. I know in my personal research that many Medeival carols appear to have been sung – including some that are incredibly beautiful. While some of them are still known today, others are largely forgotten. It only makes sense that some of the carols we know of today have come from other eras. With the collective hand-me-downs of Christmas carols, it's no doubt that we have so many to choose from.