This is a "long" comment about the "equivalence" of the restrictions about UG rule.
In "standard" natural deduction systems, we have that :
in $\forall$-I the variable $x$ may not occur free in any hypothesis on which $\varphi(x)$ depends, i.e. an uncanceled hypothesis [see e.g.Dirk van Dalen, Logic and Structure (5th ed - 2013), page 86].
With this restriction, we can prove, the Lemma :
$\forall x (\varphi(x) \rightarrow \psi(x)) \vdash \forall x \varphi(x) \rightarrow \forall x \psi(x)$
in the following way :
1) $\forall x (\varphi(x) \rightarrow \psi(x))$ --- Assumption
2) $\varphi(a) \rightarrow \psi(a)$ --- $\forall$-E (or UI)
3) $\forall x \varphi(x)$ --- Assumption
4) $\varphi(a)$ --- from 3) by UI
5) $\psi(a)$ --- form 3) and 4) by MP
6) $\forall x \psi(x)$ --- from 5) by $\forall$-I (or UG) : $a$ is not free in the Assumptions
7) $\forall x \varphi(x) \rightarrow \forall x \psi(x)$ --- from 6) by $\rightarrow$-intro, "discharging" the Assumption in 3) (please, check on your textbook : I think it is CP).
Now for the "other way".
I'll refer to Daniel Bonevac, Deduction. Introductory Symbolic Logic (2nd ed - 2003), page 215 for Universal proof (how to prove an universal conclusion) and example page 216, where the restiction is that :
Universal Generalization requires that the variable be completely new to the proof.
We proceed as follows :
1) $\forall x (\varphi(x) \rightarrow \psi(x))$ --- Assumption
2) $\forall x \varphi(x)$ --- Assumption
3) (we want to) show : $\forall x \psi(x)$
4) $| \quad$ to show $\psi(a)$ we assume the constant $a$ new to the proof
5) $| \quad \varphi(a)$ --- from 2) by UI
6) $| \quad \varphi(a) \rightarrow \psi(a)$ --- from 1) by UI
7) $| \quad \psi(a)$ --- from 6) and 5) by MP
having proved that an arbitrary object $a$ "is $\psi$", we may conclude :
8) $\forall x \psi(x)$ ("crossig" the show).
Finally, we apply $\rightarrow$-intro (or CP) to get :
9) $\forall x \varphi(x) \rightarrow \forall x \psi(x)$, discharging the Assumption 2).
I hope it can help ...