The word "Baphomet" first appears in the historical record in 1307 — the year King Philip IV of France arrested all the Knights Templar in France simultaneously, on a single Friday morning (Friday 13 October — the likely origin of Friday the 13th as unlucky). The charges against the Templars included heresy, sodomy, spitting on the cross and — most significantly for our purposes — the worship of an idol called "Baphomet."
Under torture, some Templars confessed to venerating a bearded head, a cat, or an idol of various descriptions. The confessions were wildly inconsistent — different Templars described entirely different things. This inconsistency is itself significant: it is exactly what you would expect from confessions extracted under torture, where the prisoner says whatever they believe the interrogator wants to hear. Most historians of the Templar trial regard the idol accusation as a fabrication — part of Philip IV's campaign to destroy the order and seize its wealth.
The etymology of "Baphomet" remains genuinely uncertain. The most widely accepted scholarly theory is that it is a corruption of "Mahomet" (Muhammad) — the medieval French spelling of the Prophet's name — which would make the accusation a charge of secret Islamic sympathy, plausible given the Templars' long presence in the Holy Land and their inevitable contact with Islamic culture. Other theories include an Atbash cipher (a Hebrew letter substitution code) of the Greek word Sophia — meaning wisdom — which would make Baphomet a coded reference to divine wisdom, entirely consistent with the Templar tradition. The cipher theory is elegant but unverified.