Legendary creatures sometimes have lairs which grant the creature additional ability while fighting or interacting in their lair.
Unless otherwise stated, lairs are like a creature (they cannot be attacked, and have no HP). The lair abilities can go off as long as the legendary creature is in the lair, and the lair is in tact (or exists).
Lair actions/abilities always go on initiative count 20, losing ties (they have zero DEX, or no ability scores), and have 1 AP. Lair abilities cost 1 AP. The DM or legendary creature chooses which lair action to do.