Where does CiviCRM store Merge 'history'?
An activity gets recorded when you merge and it looks up the target contact via that.

Use $winnerContact = civicrm_api3('Contact', 'getmergedto', ['contact_id' =&gt; $contactId]).

See also https://github.com/civicrm/civicrm-core/blob/5.20.2/api/v3/Contact.php#L1275