This is because of what it means for a piece of music to be "in a key".
The perception of a piece of music being in a key is the result of two things:
- The audible use of a certain scale or more than one related scales (e.g., different types of minor scales).
- The audible presence of a tonal center.
Ok, so what's a tonal center, and what makes it audible? A tonal center is a single note that all of the harmony (and melody) "leads" towards. When a piece of music has an audible tonal center, that means that when we listen to it, we are given a sense or feeling that we could hum the last note of the piece or passage if it were omitted.
Our brains are led to this note by the preceding notes and chords. Two major musical devices lead us to the tonal center: circle of fifths progressions and leading tones.
In case you're rusty on those, a circle of fifths progression is one where the root notes of each chord in the progression is a fifth below the previous root. As root notes descend by fifths, listeners tend to feel as if the music is moving from a more musically "tense" or "unstable" sound to a more musically "calm" or "stable" sound.
Leading tones are notes that are part of a more unstable chord that move to a note a half-step away in a more stable chord. The ultimate example (as far as I know) of a circle of fifths progression with leading tones giving the listener a sense of a tonal center is a V7 - I chord progression. In the key of C major, the V7 chord is G-B-D-F, and if the next chord is a I (C major) chord, we hear the G stay in place (or move down to C in the bass - a circle of fifths progression), the B as a leading tone up to C, and the F as a leading tone down to E. When we hear that, we are fairly well convinced we've just heard a cadence in C major, which will give us the feeling that the piece or passage is in C major, unless something comes along to shatter that impression.
Ok, so why can't we do that with a diminished i chord? Say, a G7 chord followed by a C diminished triad? G would move down a fifth in the bass to C, B would still move by a half step up to C. D would go up a half step to Eb, and F would go up a half step to Gb. So there's a circle of fifths and leading tones!
The problem is, we will also hear that final C diminished chord as unstable. Chords with diminished fifths are heard as different from chords with perfect fifths, and the diminished fifth sound is called "unstable".
The materials I can find online in a short time only talk about stability with reference to a tonal center and established harmony, so that would seem to imply that we could establish a tonal center around a diminished chord and make that chord sound stable, but experience tells us otherwise. We do know that the harmonic series is important in human perception of music, and I think that is part of the answer for instability. The first interval we find in the harmonic series after the octave is the perfect fifth, which is why the circle of fifths is important and also why "most" chords contain perfect fifths, and it is almost certainly why chords that contain diminished fifths sound "unstable". They are missing the most important element of the harmonic series and they have a note that is a half step away from that most important element.
Our ears/brains a unsettled by being so close to that "consonant" or "stable" feeling but not quite there. Also note that the diminished fifth or tritone is a half step above a perfect fourth, which as the inversion of the perfect fifth can also feel relatively stable. So the tritone can be very unsettling. Remember that it was considered "the devil's interval" during the renaissance.
That leads us back to the primary reason why we can't have a tonic chord be a diminished chord is because diminished chords contain tritones and no fifths, and so we will never have a feeling like we have "come back home" (harmonically) to a diminished triad.
What's the difference between "modal music" and "tonal music"?
What's the difference between a tonal center and a guide tone?
What is a "Stable" Chord?
Bonus thought: Notice the V7 chord in a major key contains a diminished triad, e.g., in C major, G7 has the B, D, and F notes of a vii(dim) chord. That diminished triad is part of what strengthens our desire to hear the V7 chord resolve to the I. The tritone is more unstable and drives us to want a return to stability.