In general, this works (maybe just in recent Tor clients) because Tor will handle
the connection to www.xxxxxxxxxxxxxxxx.onion as a connection to
xxxxxxxxxxxxxxxx.onion. The encapsulated HTTP/HTTPS connection contains the
subdomain in the Host: header (and in the case of HTTPS, the SNI
part of the TLS handshake), so the underlying web server knows what domain
the client actually wants.

Be aware that there might be some issues with older tor clients
and tools (possibly things like torsocks) that have issues addressing
subdomains like this (since they don't resolve the subdomain as a
connection to the root onion domain).