The RFC treats .localhost as a full TLD. I believe Windows does as well, as does Ubuntu (using default systemd-resolved), but macOS doesn't seem to resolve .localhost by default, necessitating the host file trickery.
Of course, in the early internet, the difference between a TLD and a host name weren't quite as clear as they are right now.