Lorenz gauge for non-homogenous wave equations in vacuum 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?
 A: given I perform a gauge transformation:
$(\vec{A},\phi)->(\vec{A'},\phi')$
Such that,
$\vec{A'} = \vec{A} + \nabla f$
$\phi' = \phi - \frac{\partial f}{\partial t}$
The new potentials, $\vec{A'},\phi'$, Leave the field invariant.
Performing the actual gauge transformation would change the potentials in the potential formulation of maxwell equation to be $\vec{A'}$ and $\phi'$
Suppose further, that aswell as leaving the field invariant, we would also like the new potentials  $\vec{A'},\phi'$
To satisfy the condition that :
$\nabla \cdot \vec{A'} + \mu_0 \epsilon_0 \frac{\partial  \phi'}{\partial t} = 0$
Thus, by  substituting the definition of $\vec{A'},\phi'$ into the lorenz gauge condition. We are essentially saying this: Given the potentials  $\vec{A'},\phi'$ satisfy the lorenz gauge condition, AND they are in a form that leaves the field invariant. What should  the function "f" be?
If we can prove than an "f" exists given the previous 2 statements, then we have shown that:
Given the potentials $\vec{A'},\phi'$ satisfy the lorentz gauge condition, they can be written in a form that leaves the field invariant. Aka, we can prescribe the divergence of $\vec{A'}$ to follow the lorenz gauge condition. And the potentials still gives the correct E,B field.
Let's solve for the function F, to prove that F exists!
$\nabla \cdot \vec{A'} + \mu_0 \epsilon_0 \frac{\partial  \phi'}{\partial t} = 0$
Sub in:
$(\vec{A'} = \vec{A} + \nabla f$),
$(\phi' = \phi - \frac{\partial f}{\partial t})$
$\nabla \cdot (  \vec{A} + \nabla f ) + \mu_0 \epsilon_0 \frac{\partial   }{\partial t}(\phi - \frac{\partial f}{\partial t}) = 0$
$\nabla \cdot  \vec{A} + \nabla^2 f  + \mu_0 \epsilon_0 \frac{\partial \phi  }{\partial t}-\mu_0\epsilon_0 \frac{\partial^2 f}{\partial t^2} = 0$
$\nabla^2 f  -\mu_0\epsilon_0 \frac{\partial^2 f}{\partial t^2} = -(\nabla \cdot  \vec{A} + \mu_0 \epsilon_0 \frac{\partial \phi}{\partial t})$
note the function on the right isn't the same as what you have gotten.
This IS a solvable equation( "inhomogenous wave equation"). meaning F exists. Meaning the potentials can be written in a form that leaves the field invariant whilst also satisfying the lorenz gauge condition.
To answer your question more directly, this is the conditions on F such that the new potentials satisfy the lorenz gauge
