They have nothing to do with it... (Sorry, the AI text is faster for me)
What we do know
The Knights Templar were suppressed between 1307 and 1312; their assets were largely transferred to the Knights Hospitaller. There is no documentary evidence linking them to Masonic lodges during the 14th to 17th centuries.
Modern Freemasonry originated in the British Isles in the early 18th century (Grand Lodge of London, 1717), inheriting customs from the Scottish/English stonemasons' lodges (operative) of the 16th–17th centuries and adding Enlightenment ideas (sociability, philanthropy, symbolic ritual).
The “Templar legend” within Freemasonry emerged in the 18th century out of romantic taste: Ramsay's Discourse (1737) and high degree rites (e.g., the German Strikte Observanz, or the Templar degrees of the Scottish Rite/York Rite) adopted Templar symbols and stories, but as a founding myth, not as actual genealogy.
Today there are Masonic orders called “Knights Templar” (especially in the York Rite), but they are modern Masonic bodies with no legal or institutional continuity with the medieval Order of the Temple.
Summary: the relationship is symbolic and ritualistic, not historical or organic.