The shares of company that is getting merged are suspended from trading from the record date onwards. So whoever bought the shares before suspension is eligible for getting the shares.
Take HDFC’s merger with HDFC Bank as example. The record date was set as July 13, 2023 and the shares also stopped trading from that day onwards. So whoever had bought shares of HDFC before July 23, 2023 would be eligible for getting shares of HDFC Bank.