If we do the following gauge trasformation for magnetic potential and electric potential :
$$\vec A(\vec r,t)'=\vec A(\vec r,t) + \nabla f(\vec r,t)$$ $$\phi((\vec r,t)'=\phi((\vec r,t) - \frac {\partial f(\vec r,t)}{\partial t}$$
Then for simplicity we do:
$$\vec A(\vec r,t)'=\vec A(\vec r,t)$$ $$\phi((\vec r,t)'=\phi((\vec r,t)$$
We simply change the name. We consider the potential with gauge our new original potentials.
Then we have:
$$(\triangle - \frac 1{c^2}\frac {\partial^2}{\partial t^2}) \vec A(\vec r,t) - \nabla[\nabla \cdot \vec A(\vec r,t) + \frac 1{c^2} \frac {\partial\phi(\vec r,t)}{\partial t}]=-\mu_0\vec j_{free}(\vec r,t)$$
$$\triangle\phi(\vec r,t) + \frac{\partial}{\partial t}\vec A(\vec r,t)=-\frac {\rho_{free}(\vec r,t)}{\epsilon_0}$$
Then we consider the Lorenz gauge:
$$\nabla \cdot \vec A(\vec r,t) + \frac 1{c^2} \frac {\partial\phi(\vec r,t)}{\partial t}=0$$
Then in order for our initial gauge to be valid in our Lorenz gauge we simply replace the potentials in the above equation:
$$\nabla \cdot \vec A(\vec r,t)' + \frac 1{c^2} \frac {\partial\phi(\vec r,t)}{\partial t}'=g(\vec r,t)$$
And in the end we find that in order for our initial gauge trasformations to be valid in the lorenz gauge we need to have:
$$(\triangle - \frac 1{c^2}\frac {\partial^2}{\partial t^2})f(\vec r,t)= g(\vec r,t)$$
And How exactly this satisfied the Lorenz gauge?