It was a side effect of the vis viva controversy described in What was the vis viva controversy, including its philosophical aspects? about what to call the "quantity of motion", momentum (vis mortua, dead force) or kinetic energy (vis viva, living force). Since the conservation of $mv^2$ in elastic collisions led to singling out vis viva as a useful concept one could say that it played a part in relating it to mechanical work, indirectly. Other concepts and interrelations in mechanics were also clarified in the course of this "debate about words" resulting in the classical presentations of mechanics by Euler and D'Alambert that we are used to.
The insight on work came from Boscovich in De Viribus Vivis (1745), it is reflected in the second edition of D'Alambert's Traite de Dynamique (1758), which became a standard text. Based on the work of Costabel, in D'Alambert and the Vis Viva Controversy Carolyn Iltis explains Boscovich's thought process, which is metaphysical, and a bit murky:
"Employing both the ancient scholastic categories and the new mathematical methods of his time, Boscovich discussed the graphical representation of a pressure applied through a time and a force applied over a distance... The pressure, an active presence (puissance), passes into action not by multiplication of effects but by generating a two-dimensional image adequately rendered only by geometry.
Without taking a position on the definition of force, Boscovich measured
the velocity acquired as a ratio composed of the pressure and its duration. A geometrical image is generated by the line representing the pressure with time as the second dimension of the diagram. The pressure is thus a function of time. Interpreting this in modern terminology, the momentum $mv$ would be represented as the integral of these instantaneous pressures (or impulses) over a time, or $\int mdv = \int pdt$.
Boscovich suggested that, if the time coordinate is replaced by the space traversed and the pressure coordinate by the force which at any instant produces the velocity proportional to it, a second aspect of the phenomenon is represented. Boscovich, however, explained neither this substitution nor the introduction of the concept of force. The new term 'force' must be interpreted as an entity proportional to the velocity engendered at any instant. If the pressure coordinate is changed to the
force and the time coordinate to the space then the new geometrical image
producing the velocity would be represented in modern notation as $\int Fds$. We would then interpret vis viva as $\int mvdv = \int Fds$ (where $ds=vdt$). Boscovich does not bring the mass into this analysis.