When TeX expands \the\count0, it sees that the thing to be printed is the contents of a \count register, therefore it looks for a 〈number〉 after \count (the number of the \count register to be printed). This “looking for” process consists in expanding all tokens from the input stream until finding an unexpandable token that doesn't fit in the grammar for a 〈number〉 given in the TeXbook p. 269. A 〈space token〉 always ends this process and becomes part of the 〈number〉 (it is gobbled by the 〈number〉 scanning process), but no more than one—see Grammar complements below. A \relax token also ends the process but doesn't become part of the 〈number〉, so TeX will use it for further processing of the input stream.
Note: in many cases, \relax does nothing, but in some cases, it may end particular processes of TeX (looking for \noalign or \omit at the beginning or end of an \halign [resp. \valign] row [resp. column]).
So, when you write \the\count0 \the\count1, the first \the applies to \count0 because the space following 0 ends a 〈number〉. \the\count0 (with ending space) always expands to the contents of count register 0 and adds no spurious space to the input or horizontal list.
\the\count1 prints... something that depends on what follows the 1. If more digits follow (possibly after expanding macros), the number of the register to be printed can be larger than 1. With a single quote following the 1 as in your example, the 〈number〉 is terminated and the contents of count register 1 is printed. When you can't be sure about what follows (macros not under your control), terminate the 〈number〉 with a space token; it will be gobbled. \relax is a popular alternative and always finishes a 〈number〉, but as pointed out in the above note, it then remains in the input stream, which may have undesirable consequences in some particular cases (see towards the end of this answer).
When you write \the\count0\the\count1', things are different for the first \the\count, because after 0, TeX is still expanding tokens looking for the next digits of the 〈number〉 that started with 0. Since \the is always expandable, it is expanded. \the\count1 expands to 34 in your example; as a consequence, this 34 becomes part of the first 〈number〉, which is 034, i.e. decimal 34 since the 〈number〉 didn't start with a single or double quote that would indicate octal or hexadecimal notation. Thus, in your example:
\the\count0\the\count1'
(with no space inside) prints the contents of count register 34 followed by an apostrophe, which you can verify by setting for instance \count34=77 (followed by a space token or by \relax) earlier in your document. Of course, in normal operation, you shouldn't write to \count registers without first making sure that they aren't already used for something else (see “scratch registers”).
Grammar complements
After unrolling the first grammar production rules for 〈number〉 (see TeXbook p. 269; these allow for optional plus, minus signs and spaces at the beginning of a 〈number〉, as well as coercion of an 〈internal dimen〉 or 〈internal glue〉 into a 〈number〉), you'll arrive at the production rules for a 〈normal integer〉:
〈normal integer〉 → 〈internal integer〉
| 〈integer constant〉〈one optional space〉
| '〈octal constant〉〈one optional space〉
| "〈hexadecimal constant〉〈one optional space〉
| `〈character token〉〈one optional space〉
where the ', " and ` are character tokens of category code 12 (“other”), 〈one optional space〉 is defined by:
〈one optional space〉 → 〈space token〉 | 〈empty〉
and 〈integer constant〉 matches any non-empty sequence of decimal digits with category code 12. The production rule
〈normal integer〉 → 〈integer constant〉〈one optional space〉
(one of those for 〈normal integer〉) is used for all 〈number〉s of your example, and the 〈space token〉 is the one we mentioned above, that becomes part of the 〈number〉 when present (but only one).
\par,\hbox,\vboxetc. command, assignment such as\def,\edef, addition, substraction, mult and div. on counters, etc.). Macros are expanded, this is their very purpose, but other commands are also expanded, such as\the. This can be triggered by a simple\expandafter(does one expansion step), by an\edefor\xdef(recursive expansion) or simply by being the topmost token in the input stream, and follows the same principle as for macros: this acts on the end of the input stream (...) – frougon Aug 01 '19 at 06:17\thecan do “smart things” on the first expansion step:\thebehaves differently if the following token is\count, (...) – frougon Aug 01 '19 at 06:44\dimen,\font, etc.\numexpr,\dimexprand\glueexpr(three e-TeX expandable primitives) do interesting things in only one expansion step (this must be the case for all expandable TeX primitives, otherwise one would have to define what “intermediate states” are, and one would reach the next “intermediate state” in a single step by definition). (...) – frougon Aug 01 '19 at 07:01\directluaeven more, it is also expandable in a single step and can even perform arbitrary user-controlled assignments, something that can't happen in Knuth's TeX! – frougon Aug 01 '19 at 07:01\ifnum,\ifcat,\ifx,\ifodd, e-TeX's\ifcsname, all\iffoobarconditionals defined with\newif\iffoobar, etc., are expandable in one step (i.e., it is sufficient to have one\expandafterhit one of these tokens in order to evaluate the condition and remove the “true branch” from the input stream when the condition is false). But there are subtleties due to the fact that TeX works in a stream-oriented way, pulling tokens as it needs; often, the\elseand\fitokens need special care; i.e., you have (...) – frougon Aug 01 '19 at 15:10\elseor a\fiin their arguments that you didn't expect. In order to understand better what I mean here, read up to page 213 of the TeXbook as well as the answers to this question (at the time of this writing: mine and egreg's answer). – frougon Aug 01 '19 at 15:10