The sentence learnt at school is not perfectly correct. It should not be :
In school, I was taught that only metals less reactive than hydrogen will form at the cathode.
It should have been modified by adding "at comparable ionic concentration", to give :
In school, I was taught that only metals less reactive than hydrogen at comparable ionic concentration will form at the cathode.
As an example, in $1 M$ solution of $\ce{Pb^{2+}}$ or $\ce{Sn^{2+}}$ or $\ce{Ni^{2+}}$, containing also $\ce{H+}$ with the same concentration $\ce{[H+]} = 1 M$, the metals $\ce{Pb, Sn, Ni}$ will not be deposited by electrolysis. $\ce{H2}$ will be deposited before the metals, as their redox potentials are too negative, being respectively $-0.13 V, -0.14 V$, and $-0.23 V$, and because of the redox potential of $\ce{H2/H+} = 0 V$
But in non-acidic solution, the situation is reversed. In the same $1 M$ solutions of $\ce{Pb^{2+}, Sn^{2+}, Ni^{2+}}$ but with $\ce{[H+]}$ = $\ce{10^{-7}}M$, the redox potential of $\ce{H2/H+}$ becomes very negative, being = $-0.41 V$. The metals are then deposited by electrolysis before $\ce{H2}$, because at $p$H $7$, all three redox potentials are less negative than $-0.41 V$