So if we are in the key of G major, an f sharp has an alteration (sharp) but is not an accidental. In the same key, an f has an alteration (none) which requires an accidental (natural) to be printed.
In lilypond we explicitly represent pitches as a step plus alteration (if an alteration is omitted, it is assumed as none, not as following the key signature). This is a design decision that allows the notes to be entered as specified pitches, regardless of the key signature. Thus, the pitches do not change when the key signature changes; only the display of the pitches changes.
Personally, I am glad the lilypond creators made this choice. I always enter the pitches I want to hear, and the display of those pitches can be easily changed.