Actually is not a guitar problem, but all 12-TET tuned instruments have this, it is just a side effect of harmonic math. In the guitar case it is not only the tuning that counts, also the material the string are made and the diameter of the strings count to the final frequency, and we are using parallel frets so applying the same distance to different strings. There are guitars with not parallel frets that try to compensate for the diameter variation. But that’s all math and understanding, cause when you tune your guitar and just play you are in another world were "thought is the killer of flow"; so just play and enjoy the sound. :D
There are two type of “not parallel” frets and neither have anything to do with the diameter of the strings.
Different guitarists use different diameter strings because the diameter determines the tension when you tune to pitch. Different people prefer different tension. Most shredders prefer light tension. Most jazz players prefer high tension.
The diameter is compensated at the bridge and in some guitars the nut. When you press a thin string to a fret, the center of the string is closer to the fret than when a thick string is pushed to the fret. Thicker strings compensate for this by using slightly longer length which you can adjust at the bridge.
One type of non parallel frets are called true temperament frets. They are sort of parallel but squiggly. This results in better intonation closer to that of a piano.
Another type of non parallel frets is multi scale or fanned frets. This allows the bass strings to have a longer scale length, which allows you to use relatively thinner strings for bass notes. This is important because when strings get thicker relative to their length, they start to behave more like cylinders with thickness rather than ideal springs, and sound rather nasty because harmonic overtones are out of tune with the fundamental.
Yes, the diameter is compensated at the same time as the tension.
When the string's action is higher above the frets, the tension increases more when fretted than open, to a greater degree than low action.
So the saddle for that string needs to be positioned such that the plucked portion of the string is slightly longer than it would need to be if the tension were the same as the open string.
Another thing that’s not been mentioned here: there is a relationship between volume and pitch. In short, you strike a string hard and it goes a bit sharp. The issue is that the tonal math makes a linearization of the string physics, but the highly activated string is effectively a little tighter than the idealized version.
Humans are also not perfect at fretting with the exact same pressure every time, or without inducing some bend in the strings. This is really noticeable with the G string which always sounds out of tune while playing, because our tuning system gives it a half-step-down intonation as a trade-off to make it easier to form chords.
James Taylor compensates by tuning everything down a few cents, between -12 at the low E and -3 at the high E, with a little break in the pattern with -4 cents at the G to deal with its weirdness. Good electronic tuners have "sweetened" presets which do something similar.
Peterson guitar tuners can do custom tunings, and have the James Taylor tuning built in as a preset. (On Peterson tuners, it's called the 'acoustic' preset, but is actually the JT tuning.)