The restriction is in the scanner, tex's "eyes" in the texbook terminology. Any sequence of characters may be used as a command name, however after a character of catcode 0 (normally \ ) then tex scans the next non-letter (character of catcode other than 11) or a contiguous sequence of letters, and tokenizes it as a single csname token.
This means that \foo123 normally parses as the token \foo followed by the three tokens 1, 2, 3. Unless you make digits catcode 11. Similarly \section* is normally the token \section followed by the token *.
environment names use do not require to parse the name via the escape character, (they use the \csname primitive but that's an implementation detail so \begin{tabular} accesses \tabular but \begin{tabular*} accesses the command with name tabular* (not the two tokens that would normally be generated by parsing \tabular*).
So technically it would be quite hard to not allow digits (or other characters) in environment names, especially when latex was designed there was not the memory available to add that kind of character-by-character check.
\expandafter\def\csname mycommandwithanumber123456\endcsname{}you'll define a command\mycommandwithanumber123456. The environments are created using the\csname...\endcsnamepair, so it's fine. – Phelype Oleinik Apr 05 '19 at 22:36\expandafter\def\csname macro2\endcsname{command output}is valid syntax. You then must use it via\csname macro2\endcsname. – Steven B. Segletes Apr 05 '19 at 22:36