This question is related to different motivations for the need of gauge invariance in QFT. I was introduced to gauge invariance in the following way.
Consider a vector field $A^\mu(x)$, with $x\equiv x^\mu$. The most general free Lagrangian that is Poincaré invariant involving the field $A^\mu$ and containing at most two derivatives is given by
$$\mathcal{L}=a_1\partial_\mu A_\nu\partial^\mu A^\nu+a_2(\partial_\mu A^\mu)^2+a_3 A_\mu A^\mu,$$
where $a_1,a_2,a_3$ are non-zero parameters. If one wants to describe a particle of given spin and aribtrary mass, this Lagrangian would containt two too many parameters; only one of the $a_i,i=1,2,3$, is needed. Furthermore, $A^\mu$ contains $4$ independent polarizations as $\mu=0,1,2,3$. If $A^\mu$ is set to describe electromagnetic waves which have just two polarizations, then the field $A^\mu$ contains two too many degrees of freedom. These two problems can be solved by imposing that the action is invariant under the transformation
$$A_\mu\rightarrow A_\mu^{'}\equiv A_\mu-\partial_\mu\alpha,\quad S[A]=S[A'].$$
This constraint the coefficients $a_1,a_2,a_3$ as; $a_1=-a_2,a_3=0$. By fixing $a_1=-1/2$, the Lagrangian then takes the form
$$\mathcal{L}=-\frac{1}{4}F_{\mu\nu}F^{\mu\nu},\quad F_{\mu\nu}\equiv \partial_\mu A_\nu-\partial_\nu A_\mu.$$
From this Lagrangian, one finds the Maxwell equations as equations of motions which impose only two degrees of freedom on $A^\mu$.
Another motivation of the need of gauge invariance in QFT is given in chapter $8$ of Weinberg The Quantum Theory of Fields. My understanding is that because the quantized vector field $A_\mu$ does not transform as a true four-vector under Lorentz transformation, that is it transforms as
\begin{equation}\tag{8.1.2} U_0(\Lambda)A_\mu(x)U_0^{-1}(\Lambda)=\Lambda_\mu^{\: \nu}A_\nu(\Lambda x)+\partial_\mu\Omega(\Lambda x). \end{equation}
Then, to include an interaction term between a matter field and $A_\mu$, we require the action of the interaction between the matter field and $A_\mu$ to be invariant under the following gauge transformation
\begin{equation}\tag{8.1.3} A_\mu(x)\rightarrow A_\mu(x)+\partial_\mu\epsilon(x). \end{equation}
It thus seems that gauge invariance was introduced to ensure Lorentz invariance, as detailed in this question.
My question: how are these two approaches to the need of gauge invariance in QFT related; more specifically, how does the second approach ensure that the field $A_\mu$ only contains two degrees of freedom that describes an electromagnetic wave?
As indeed, the first approach was build to be Lorentz invariant, and thus its relation to the second approach is immediate; it is already Lorentz invariant (at least to my understanding).