Isobaric entropy relation from isothermal Gibbs free energy relation I have been given a problem to derive a relation for change in entropy from change in Gibbs free energy:

Starting with the isothermal equation
$$G(p_2) = G(p_1) + nRT\ln\frac{p_2}{p_1}\label{eqn:1}\tag{1}$$
derive
$$S(V_2) = S(V_1) + nR\ln\frac{V_2}{V_1}\label{eqn:2}\tag{2}$$
using the relation
$$\mathrm dG = V\,\mathrm dp - S\,\mathrm dT.\label{eqn:3}\tag{3}$$

The derivation wants you to assume that pressure is constant and thus $\mathrm dp = 0,$ and \eqref{eqn:3} can be arranged to
$$\left(\frac{\partial G}{\partial T}\right)_p = -S.\label{eqn:4}\tag{4}$$
Now I understand that then differentiating \eqref{eqn:1} w.r.t $T$ and using the fact $p_1 V_1 = p_2 V_2$ (for constant $T)$ can produce the required equation \eqref{eqn:2}.
However, I don't understand quite how we can justify the derivation of an isobaric equation from an isothermal one as this method appears to. Equation \eqref{eqn:1} describes isothermal processes and is a function of pressure, $p_2.$ How is it valid then to suddenly say now pressure is constant and therefore use \eqref{eqn:4} when in equation \eqref{eqn:1} the pressure is clearly not constant?
Might it have something to do with Gibbs free energy being a state function meaning, once there is a relationship for it, constraints (for different state variables) can be changed to derive new relationships using a different constraint?
For an ideal gas at constant temperature $\Delta H=0$, so $\Delta G=-\Delta (TS)$, and, at constant temperature, $$\Delta G=-T\Delta S$$