My friend and I were having this discussion and it brought upon an interesting question. My friend believes that a fugue can, in a theoretical sense, have n number of voices - which is true of course. But I wonder how many voices it would take before the fugue turns into a hot mess with no rhythmic identity. Do you have any examples of fugues that were written for more than 6 voices?
Giving a fugue some "rhythmic identity" is (like most issues in writing counterpoint) just a matter of knowing the right standard tricks to use. Make the notes of the subject either longer or shorter than the rest of the counterpoint and they won't get "lost in the mix". That's all there is to it.
Bach knew that sort of trick very well. Take the triple fugue in 5 parts, WTC book 1 in C# minor. The first subject only uses whole and half notes, the second is almost all 8th-notes, and the third is mostly quarter notes. Simples!
The practical limit is about 8 parts, simply because with a single subject the exposition becomes over long. For a double fugue in 8 parts, the exposition is no longer than a 4 part fugue.
Many fugues for solo keyboard instruments are in three parts because of the practical performance issues, especially with a fast tempo. But Bach wrote a few 5-part fugues, and there are a few examples with more - for example Sorabji's colossal fugue in the Second Organ Symphony, which gradually builds up to 7 parts over a total duration of two hours. (The first subject on its own is more than a minute long, and the exposition is longer than most complete fugues by Bach.)
The Cherubini example isn't really "extreme". That book was the standard counterpoint textbook for the Paris Conservatoire (where Cherubini just happened to be employed as the professor of counterpoint!) and any student would have been expected to construct that sort of fugue in an examination room. (The word "construct", rather than "compose" is a deliberate choice. As I already implied, this is about learning the right basic moves and how to string them together, not about "being inspired" as a composer).
Eight part fugues were a "normal" feature of works with double (i.e. eight-part) choirs.
A 19th-century composer called Pietro Raimondi (who ended up as maestro di cappella at St Peter's Rome, so he wasn't a complete weirdo oddball) wrote things like sets of three four-part fugues, each in a different key, which could be performed separately or simultaneously as a single 12-part piece. There are a few of his compositions on IMSLP, but they are only published in separate parts so you will have to put the score together yourself.
In fact those were just experiments - he went on the compose things like three complete oratorios (each for chorus, soloists, and orchestra) on different subjects, which could be (and actually were) performed either independently or simultaneously.
So the best answer to "what is the theoretical limit to the number of voices" is probably "nobody has discovered it yet" :)
First the example...
A Treatise on Counterpoint and Fugue By Luigi Cherubini
...but that seems an extreme example.
In Bach's Well Tempered Clavier most of the fugues are 3 or 4 parts. I think it's worth noting that during episodic passages the texture often lightens with a voice dropping out.
The Credo in Bach's B Minor Mass has a 7-voice fugue for 5 voices and 2 violins, plus basso continuo.
Bach's motet "Komm, Jesu, komm" BWV 229 has a brief 8-voice fugato on the text "der saure Weg wird mir zu schwer," roughly, "this blasted way is getting too hard for me." That may be the master reporting a practical limit.
As for a theoretical limit, Pietro Raimondi, mentioned in guest's answer, seems to have composed a 64-voice fugue for 16 4-part choirs, now lost. Grove's Dictionary is too polite to call it a hot mess, instead calling it utter futility.