A piano or other keyboard instrument can be tuned to play notes in a given key as close as practically possible to just intonation. But of course attempting to play in a different key on that keyboard would sound noticeably out of tune to varying degrees. So the concept of equal temperament was devised where each note was equally adjusted in a manner that allowed all 12 potential musical keys to be played without sounding too out of tune.
Fretted instruments such as a guitar, are set up to be capable of being in tune with a piano or other keyboard to the extent possible so that if you play a middle C on piano and guitar, they will be close enough to sound the same. In fact you can tune a guitar's open strings with a piano and get them exact.
But after you leave the open strings on a fretted guitar, it will typically be difficult to achieve any type of perfect or just intonation or even consistent matching of notes with an equally tempered keyboard. If you play any fretted note on your guitar you will notice that you can change the pitch simply by pressing down harder (or not as hard) on the fret. So playing style will cause the fretted notes on the same guitar to sound different depending on who is playing the notes.
Another factor that affects a guitars ability to stay in tune from open string to fretted note - would be the string height above the fret board (as Tim alluded to). A guitar with higher action will intone slightly differently between fretted and open notes than one with a lower action. In standard tuning you have 5 notes with 6 frequencies (low E, high e).
On almost any guitar, if you tune the open strings to a piano perfectly, the fretted notes will be slightly off, even if you could guarantee the exact same application of pressure to the string when pressing it down on a fret. It's a further compromise that a guitar must make because you have one string with a given gauge and tension that is expected to play 20 notes. On a piano, each piano key is tied to a unique set of strings that can be tuned the way the open strings on guitar are tuned.
Bottom line is that instruments such as keyboards and fretted instruments such as guitars, ukuleles, bass guitars, banjos, mandolins, etc. are inherently incapable of playing just intonation in multiple keys without retuning the instrument for each different key.
However, a fretless guitar or fretless bass, or instruments such as violin or viola, allow the musician to make the necessary adjustments in finger placement to play in just intonation in whatever key they choose. Thus a string ensemble or quartet can play in any key and adjust the notes to just intonation accordingly. But if you add a fretted or keyboard instrument into the mix, the strings must adjust to the fixed tuning system of the piano or fretted guitar. Otherwise one or the other will sound "out of tune". So they must all be slightly "out of tune" to sound in sync.
For more on the subject of Just Intonation read the enlightening answers to this question on Stack Exchange Music Why Just Intonation is Impractical