When NII (HNI) quota unsubscribe, the company takes the call to distribute the remaining shares in other categories i.e. retail, QIB, employee, or shareholders.
The detail about the distribution mechanism is provided in the IPO RHP document.
For example:
Paytm IPO RHP page 490 says
Subject to valid Bids being received at or above the Offer Price, under-subscription, if any, in any category except the QIB Portion, would be allowed to be met with spill over from any other category or a combination of categories at the discretion of our Company, in consultation with the JGC-BRLMs, the BRLMs and the Designated Stock Exchange, on a proportionate basis.