The figure that we now know today has a shady past to say the least. It was said to be the downfall of the Knights Templar, to the Pan-like god worshipped by Freemasons and it even gave birth to the first third political party, the Anti-Masonic Party.
The birth of Baphomet goes back to the Crusades, but not as you would think. It was told that the Infidels in the Holy land would pray to Baphomet before engaging in battle. Well....kinda. The word that we use today, Baphomet is actually the French bastardization of the word Mahomet, or Mohammad, the Prophet of Islam. Its not the first time language changed and words invented simply out of mistranslation.
This would of course lead to the fall of the Knights Templar. Hollywood can always put a spin on history and the Knights Templar are ripe for romanticizing and demonizing at the same time. I will make it though as plain as possible. The Knights Templar are a religious order created during the Crusades to help retake the Holy Land and to protect pilgrims. They ALSO invented a modern banking system which made them a powerful financial player in Europe and they bankrolled a goodly portion of the Crusades in certain areas making this humble order very wealthy.. Phillip the IV or Phillip the Fair of France was heavily indebted to the Templars by the early 1300s. Soooooooo….when Phillip started having financial troubles himself, what do you do? You eradicate the person you owe the most to. Its like planting a bomb at your least favorite credit card company headquarters. The Knights were trumped up as worshippers of "Baphomet" or secret Muslims and many were wiped out or were on the run from the law and the Church. This will give rise to the Church of Rosslyn stories as well as the Masonic/ Templar legends.
Now lets jump to the Victorians. Freemasonry was at its height by the end of the 1700s so by the early 1800s it had its haters. There was a long line of people who used the Templar story and combined it with idol worship and that is how Baphomet got its "goat-like" appearance. BUT it wasn't until Eliphas Levi did we get that Pan-like figure we now today call Baphomet. Levi, born Alphonse Louis Constant, was a bitter former Catholic and sadly a Freemason who started dabbling into the occult and became a huge influence in Victorian occultism. Baphomet will make its first appearance in a book written by him called in Dogme et Rituel de la Haute Magie, or the Dogma and Ritual of High Magic in 1856.
So...how did Baphomet get associated with Freemasonry? By mudslinging of course. In American in the 1820s rose the Anti-Masonic party, the first third political party. And they were an active political party for nearly 20 years. This will come out of the Morgan Affair which was where a Mason by the name of William Morgan threatened to expose all Masonic secrets in a book and then he disappeared, allegedly murdered. This became a keystone in a political movement to uproot the current political members who had Masonic connections. In Europe, it was no different, Anti-Masonic parties rose up and the best way to discredit them is to make them the villain, even if it makes them "devil worshippers". Masons, being ever one to make the best of a bad situation, made the goat a humorous part of Masonic lore, thus to "ride the goat".