Quick, general answer: Because chromatic notes and chords are a thing. A very commonly-used thing. You don't have to stay in the scale.
Longer answer, more specific to this instance:
You have fallen into the trap of assuming that the 'Natural minor' scale is the ONLY form of minor scale.
Until quite recently, standard teaching was that the Harmonic minor scale was the norm, sometimes modified into the Melodic minor. But they both used the sharpened leading note when ascending, which enabled a major dominant chord, a central feature of Common Practice harmony. (If Harmonic minor, Melodic minor mean nothing to you, there are plenty of online resources for basic theory, I won't try to spell it all out here.) In fact, when trying to determine whether a piece had strayed into the relative minor key, the rule of thumb was 'spot the sharpened 7th'. When a piece that starts in C major starts getting G sharps, that's a pretty good clue that we might be visiting A minor.
The Natural minor scale, with its flat 7th note, was a poor relation, mostly found in folk music. Natural, with its modal flat 7ths and lack of proper dominant chords only suited folk songs. Don't get annoyed, but there's a certain truth in that. A musical form longer than a simple song ("all you can do with a folk song is play it again, louder") will probably use different keys as a structural device. And you get to new keys through dominant-tonic relationships.