In many aspects of culture Salamanders are associated with fire, this makes no sense to me at all and I can't understand how this even came to be
The likely origins of this particular bit of folklore are actually fairly well sourced: originating with some slightly exaggerated observations of salamanders from Greek and Roman naturalists and philosophers and spiraling into the fantastical by the early Medieval era.
Naturalistic observations on the characteristics and behaviors of salamanders are recorded as early as the 4th century BCE - with Theophrastus (Aristotle's second most famous student) describing them as a type of lizard whose appearence foretold rain.[1] In the centuries after, you would see different Greek physicians and philosophers ascribe increasingly unusual abilities to the little amphibians. Theocritus would claim salamanders were a key ingredient of love potions in the 3rd century, while Nicander in the 2nd century would go so far as to describe them as the "sorceress’ lizard" - used in all sort of malevolent potions. [2]
So early on, we can already see some particular associations being made that will be important for the jump to salamander's mystical association with fire later on. Firstly - the reasonable assoctiation between salamanders and water, and secondly - an association between salamanders and general mystical attributes. But why were these assocations being made in the first place? Well, because the species of salamander the Greeks were likely interacting with were the fire salamander and alpine salamander - both of which are amphibious, active during rain, and most importantly secrete toxic mucus that cause, amongst other things, burning pain and muscle convulsions. [3] Perhaps we can already see how this will come together?
Well it does, beginning with everyone's favorite Roman Naturalist - Pliny the Elder, writing in the mid 1st century CE. Who, when describing the salamander, would recount reports that ascribed salmanders with the ability to extinguish fires due to their natural frigidity. Even though Pliny noted this purported ability with uncharacteristic skepticism, it was now in records that would be well preserved and consumed by later medieval naturalists. There is now a direct association between salamanders and control over fire. Pliny would also greatly exaggerate the toxicity of salamanders to make them seem almost mythical - claiming that if a salamander fell into a well any who subsequently drank from that well would die. [4]
Also of note is that roughly contemporary to these writings salamanders were already being associated with blacksmithing to at least some extent. With a bas-relief of a fire salamander straddling an anvil-and-forge found in the ruins of Pompeii. [5] We have reason to believe this still isn't due to individuals believing salamanders could magically cause fires - but rather because they had a supernatural ability to quench fires. With the Roman orator Aelien claiming by the early 3rd century CE that salamanders, due to being naturally extremly cold and yearning for warmth, would be drawn to the fires of blacksmiths - subsequently quenching them. As we can see, the association between salamanders and fire are gradually growning stronger, and more mythologized over the centuries as folkloric naturalism and generational exaggeration compounds on itself.
But I think most mythologists would agree that the moment of transition - from a being that quenches fire to a being of fire - is best spotted within Augustine of Hippo's "City of God", written in the 5th century CE.
"If, therefore, the salamander lives in fire, as naturalists have recorded, and if certain famous mountains of Sicily have been continually on fire from the remotest antiquity until now, and yet remain entire, these are sufficiently convincing examples that everything which burns is not consumed." [6]
Salamanders no longer quench fire, they live within fire as 'naturalists have recorded' (ie: the previously mentioned Romans and Greeks that early christian thinkers drew heavily from). Here we can see how the early recordings regarding salamanders have finally shifted, due to gradual misinterpretation into almost their exact opposite!
And, as folklore is wont to do - its mythical scale and potency only increases with time. This answer is already too long so I don't want to get into too much detail, but by the Rennaisance the supernatural association between salamanders and fire has clearly been well established within the cultural zeitgeist. With fiery salamanders appearing all throughout renaissance art and stories of salamanders scrambling out of burning fireplaces (salamanders often hibernate under, and within, rotting logs) being used as anecdotal justification for their apparent immunity to, and genesis from, flame. [7] Folklore has a remarkable way of reinforcing itself with communal, anecdotal, experience.
I hope you've enjoyed this centuries-long tale of mythological telephone!
Sources:
[1] Theophrastus; Hort, Arthur F. (1926). Enquiry into Plants, Volume II: Books 6-9. On Odours. Weather Signs. Loeb. p. 400.
[2] Wallace, Ella Faye (2018). The Sorcerer's Pharmacy. New Brunswick, New Jersey. p. 44.
[3] sossalamander.nl - Fire Salamanders
[4]Pliny the Elder; John Bostock and Henry Thomas Riley (1855).* The Natural History*
[5]Aelian; Scholfield, A.F (1958). De Natura Animalium. Loeb. p. Bk. 2, Sec. 30.
[6]Augustine of Hippo; Philip Schaff (ed.). St. Augustine's City of God and Christian Doctrine (in English and Latin). p. 454
[7]Thomas Bulfinch (1913). Age of Fable: Vols. I & II: Stories of Gods and Heroes: XXXVI. The Salamander.