The algorithm is described in eip-137.
The recursion this EIP refers to is the following line:
return sha3(namehash(remainder) + sha3(label))
I am not sure of all of the reasons for this, but I do know that hashing the values (specifically the user generated
label in some cases) allows for visual verification that the
label are truly the expected values.
ENS had an issue early on with zero-width spaces that allowed people to register what seemed like ethereum.eth, but in reality was ethereum.eth with one or more whitespaces in them. Visual inspection would have told you that these were the same values, but hashing the two values produce a different result.
There may be additional reasons for the recursive hashing, but this is one that I know of.
Thanks for the help @shane!
I have found more use cases in the ENS doc and from what I understand now is that the recursive call in namehash enables some nice lookup functionality similar to existing DNS as well as fixed length keys in the registry store.
As everything is hashed I can register a subdomain by sending
namehash('bar.eth'), web3.sha3('foo') without exposing
foo in clear text on chain. Very nice design.