The same thing happens in major keys as well. The secondary dominantV of V in C would be D7, sogiving a "V of V"V/V to V to I progression would be D7 - G7 - C. You need to make the F note sharp if you want to play a D7 chord. Or in C7 - F, using secondary dominant C7 going to F, thinking about F as being a temporary I chord. A "secondary II - V - I" in C going to F could be Gm7 - C7 - F. To have this harmony progression, the B note has to be made temporarily flat. As soon as you get to the target F major chord, you can return the B note back to B natural.
When composing or improvising, it's quite essential to have some kind of an intellectually definable idea of the harmonic context, and it can be explicated in terms of a scale. But even then the scale is just a reference grid that helps you reason about where things are. It's like a ruler that you might place on a drawing. It's not a rule about what can or cannot be done. Decide what chords you want, and then you can think about what the chords did to scale possibilities. Sometimes you find new chord combinations that do something interesting and you have to poke around to find where scale degrees could be, i.e. what harmonic contexts you could superimpose over the new situation. But you might also simply accept the chords as-is without explicating a complete scale over them. One example that comes to mind is "planing" chromatically, for example in Dm, if you descend chromatically like Am7 - Abm7 - Gm7, what scale might there be over the Abm7? Does it matter? Many people are able to use chromatic tricks like that completely fine without caring about the scale question.
As an exercise, play the following chords: C, F, G7, C, Gm7, C7, G/F, C/E, F/Eb, Bb/D, Eb/Db, Ab/C, Dm7, G7, Ab/Bb, C. What happens to the harmonic context along the way? Did the tonic really change - you did remember the initial C even after all the changes happening in the middle?