Your third paragraph relates to the Raychaudhuri focusing theorem, whose wikipedia page is not bad as a starting point <https://en.wikipedia.org/wiki/Raychaudhuri_equation>.

The focusing theorem basically says that an initially converging congruence converges more quickly in the future, and an initially diverging congruence diverges less quickly in the future.

The Raychaudhuri picture for your pair of masses is fairly straightfoward given that the small distances can effectively wash out any coupling to the metric expansion of space. If the masses are small (i.e., we're not talking about two black holes) the background gravitational metric is effectively flat, perturbed only by mass A and B. This lets us determine exactly the factors opposing recollapse of your initially-diverging mass A and mass B. We can also be confident that an initial impulse could drive the separation, with the focusing theorem behind the eventual collision between A and B.

At larger length scales the metric expansion of space becomes important, so the background gravitational metric is instead Friedmann-Lemaître-Robertson-Walker (FLRW) or similar. We can still talk about Raychaudhri focusing in that context, but we take "... will diverge less quickly in future" slightly differently depending on whether the galaxies are flying apart because of an initial impulse (i.e., the expansion is inertial), or whether there is also a cosmological constant (i.e., the expansion is accelerating).

In the inertial case, the ultimate recollapse depends on a critical value in the (average) energy-density of the whole universe. Returning to your mass A and mass B picture, in the previous case with a flat background spacetime where A and B colliding is inevitable, in the inertially-expanding spacetime the initial impulse on A and B can lead them to never meet again, even given infinite time.

In the case of a small positive cosmological constant (which best explains what we see in redshift surveys), heavy nearby galaxies will take their time to separate compared to lower-mass galaxies with similar separation, or the same heavy galaxies which formed with a larger separation. The Raychaudhuri focusing theorem adapted to this setting tells us whether the galaxies will merge or not, and this is useful in understanding the spatial extents and masses of galaxy clusters. Returning to mass A and mass B, given a positive cosmological constant, no initial impulse is necessary; the CC alone can determine whether they will be separate forever, or whether they will eventually collide.

Returning to your final paragraph, the (average) energy-density must be over some critical value for distant galaxies to come into contact with each other, and that critical value for all practical purposes only depends on the value of the cosmological constant (if any).

So far, with decades of trying to measure the average energy-density and critical value, it's safer to say that distant galaxies will lose contact with each other. There is no known mechanism to change that for arbitrary sets of galaxies.

Note that I have not discussed energy above except as energy-density (which is energy per unit volume, particularly where the volume is very very small) averaged across the entire cosmos, and the invariant masses of your A and B and of galaxy clusters.

Finally, for completeness, clusters of galaxies are known to move strikingly against the cosmological coordinates, leading to some famous cluster-cluster collisions (e.g. the Bullet Cluster). Why they don't just float at the same cosmological coordinate (remember the coordinates expand) like the overwhelming majority of galaxy clusters is a topic of active research. However, perhaps some late-time impulse could drive initially diverging galaxies (carried for all practical purposes only by the cosmological constant) into a collision in a way that matches your final paragraph. (Alternatively these collided galaxies might never have been diverging in the first place).