It didn't always have to turn into an infection as there are plenty folk methods of preventing that from happening used throughout history - from wound cauterisation to my regional bread + spiderwebs.
The latter was given a scientific explanation in modern times: the webbing contains live penicillium fungi in quantities sufficient to act against microbes.
It's very rare for a minor injury to become seriously infected to the extent that the patient's immune system can't fight it off. Even before the discovery of antibiotics, amputation was typically only used as a salvage therapy in cases of gangrene. They didn't reach for the bone saw just because you had a serious infection.
The latter was given a scientific explanation in modern times: the webbing contains live penicillium fungi in quantities sufficient to act against microbes.