Guitar strings are compensated usually just at one end, at the bridge saddle. When we fret a note the string is bent slightly sharp. Lengthening the string at the saddle helps to compensate for that sharpness compared to the ideal fret position. The problem with that is that the open string is now slightly flat which compounds some of the tuning issues that musicians with fine ears notice on chords with open strings. Nut compensation is a further correction which brings the open strings into better tune with fretted notes.
Is it necessary? 99% of all recorded guitar music is done without nut compensation. But many of of us who can hear the difference swear we'll never go back! I love it.
Talking about different keys is confusing this type of compensation with other issues. Icidentally, all instruments with notes of fixed pitch (guitars, pianos, sax etc.) are designed to equal temperament tuning, which makes all notes identical in all keys (e.g. A# and Bb are always the same frequency irrespective of what key you are playing. It is itself a compromise but ensures that pianos players don't have to re-tune all 220+ string just to go from C major to Eb major. 99% of all recored music is recorded with equal tempered tuned instruments.