First of all, note that \dospecials includes the space character, so the \catcode of the space character is turned into 12 (“other”) by the \verb macro. Second, do not forget that, in the cmtt font, the symbol for the visible space is found in slot 32, that is, precisely in the slot allotted to the space character. So, exactly as you don’t need to do anything special in order to make the \verb command typeset an “A” character when an A is found in the input, in the same way no special provision is needed in order to make a space character in the input to be typeset as a “visible space” symbol. You have to arrange things in some special way if you want spaces in the input to be translated into genuine spaces in the printout.
Of course, if a different font is used for verbatim output, it must contain a similar symbol in the same slot, otherwise the printout won’t look right: see, for example, the output of the following (compilable) code snippet:
\documentclass{article}
\makeatletter
\def\verbatim@font{\normalfont}
\makeatother
\begin{document}
Some verbatim text: \verb*|$%& and some spaces|.
\end{document}
Addition.
Expanding on @egreg’s comment, it could be remarked that, with the introduction of T1-encoded font, the arrangement described above has been made more robust than it was formerly (with OT1 encoding): indeed, under the T1 encoding, all the slots of a font that correspond to printable ASCII characters must (or should…) contain a glyph suitable for representing that same character; and even if, strictly speaking, the space character is not a printable character, nonetheless T1-encoded fonts should contain, in slot 32, exactly the glyph for the “visible space”. It should also be remarked, on the other hand, that in general OT1-encoded fonts fail to represent verbatim also other characters besides the space; for example, they also lack suitable glyphs for the {, \, and } characters.
Both these points are illustrated by the following compilable example:
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\makeatletter
\newcommand*\SetVerbatimFont[4]{%
\def\verbatim@font{\usefont{#1}{#2}{#3}{#4}}%
}
\newcommand*\ShowVerbatimFont{%
{\verbatim@font \fontname\font\/}%
}
\makeatother
\begin{document}
\setlength{\parskip}{\bigskipamount}
Some verbatim text in the default verbatim font:\\
\verb*|$%{}\~& and some spaces|\\
(it looks right).
\SetVerbatimFont{OT1}{cmr}{m}{n}
Some verbatim text in \ShowVerbatimFont:\\
\verb*|$%{}\~& and some spaces|\\
(it looks wrong).
\SetVerbatimFont{OT1}{cmr}{bx}{n}
Some verbatim text in \ShowVerbatimFont:\\
\verb*|$%{}\~& and some spaces|\\
(it looks wrong).
\SetVerbatimFont{T1}{cmtt}{m}{n}
Some verbatim text in \ShowVerbatimFont:\\
\verb*|$%{}\~& and some spaces|\\
(it looks right).
\SetVerbatimFont{T1}{cmr}{m}{n}
Some verbatim text in \ShowVerbatimFont:\\
\verb*|$%{}\~& and some spaces|\\
(it looks right).
\SetVerbatimFont{T1}{cmr}{m}{it}
Some verbatim text in \ShowVerbatimFont:\\
\verb*|$%{}\~& and some spaces|\\
(it looks right).
\SetVerbatimFont{T1}{pcr}{m}{n}
Some verbatim text in \ShowVerbatimFont:\\
\verb*|$%{}\~& and some spaces|\\
(it looks right).
\SetVerbatimFont{T1}{ptm}{m}{n}
Some verbatim text in \ShowVerbatimFont:\\
\verb*|$%{}\~& and some spaces|\\
(it looks right).
\end{document}
This is the output:

Note that the second and third paragraphs illustrate the case of two fonts that are inadequate for verbatim typesetting, showing that they not only misrepresent space characters, but also {, }, \, and ~. On the other hand, the last two paragraphs use PostScript fonts (Courier and Times) with T1 encoding, and you can see that the output is correct.
an explicit space token is inserted for each space character.: perhaps more precisely space character is tokenized to active space token, the latter being defined to expand to (essentially) the "control space". – Aug 28 '18 at 08:17