The merger of neutron stars faciliates the r-process, where nuclei capture neutrons in a highly neutron-rich environment. This is where the neutron capture occurs more quickly than beta-decay processes can take the newly produced nuclei back towards the nuclear valley of stability (the locus of $A$ vs $Z$ that maximises the binding energy per nucleon for a given value of $A$).
When nucleons are inside a neutron star the bulk are in the form of neutrons, with a crust of neutron-rich nuclei. The equilibrium nucleus is set by the ambient density and becomes increasingly heavy and neutron-rich as one moves into the neutron star and ultimately it becomes more energetically favourable for free neutrons to exist outside nuclei and the nuclei dissolve into a sea of degenerate neutrons and a small fraction of protons and electrons.
In a neutron star merger the neutron stars are tidally disrupted and the gravitational potential energy of the merging pair is released. This can be used to unbind some fraction of the mass. That material, a dense mixture of neutron-rich nuclei and free neutrons is able to rapidly evolve in an out-of-equilibrium way, via nuclear decays and the r-process. The r-process continues to add neutrons to seed nuclei, originally from the neutron star crust, until they reach one of the magic numbers for a closed shell of neutrons - 50, 82, 126. Here, the relative stability of the nuclei against further neutron capture allows beta decay back towards the valley of stability and the formation of a broad "hump" of "r-process nuclei" with mass numbers around 82, 130 and 196.