HSDir stands for hidden service directory. When an onion service starts, it writes a descriptor listing its introduction points and signs it, then uploads it to several HSDir relays. When you visit the service, your client works out which HSDirs should hold that descriptor and fetches it from them. Without HSDirs, there'd be no way to look up a service by its address.

Which relays hold a given descriptor isn't fixed. The relays are arranged on a hash ring, and the position for each service changes every day based on a blinded version of its key and the current time period. That rotation makes it hard for an attacker to set up relays in advance at exactly the right spot to watch a particular service.

The v2 design had a real weakness here: HSDirs could see the onion address of every service they stored, so malicious relays harvested addresses by the thousand. v3 fixed this by having services upload descriptors under blinded keys and encrypting the contents. An HSDir now stores a blob it can't link to an address unless it already knows the address.

Relays get the HSDir flag automatically after being stable for long enough; operators don't need to do anything.