Suppose $f$, $g$ $\in$ $\mathcal{S}$ the space of Schwartz functions and consider the Fourier transform $\mathcal{F}_m:\mathcal{S}\to\mathcal{S}$ defined by
\begin{equation} \mathcal{F}_m(f)(x)=\frac{1}{\sqrt{2\pi}}\int_{-\infty}^{\infty}dy\exp(-ixy)f(y). \end{equation}
In physics, the Plancherel formula
\begin{equation} (\mathcal{F}_m(f),\mathcal{F}_m(g))=(f,g) \end{equation}
where
\begin{equation} (f,g)=\int_{-\infty}^{\infty}dxf(x)^*g(x),\tag{1} \end{equation}
is typically proven as follows:
\begin{equation} (\mathcal{F}_m(f),\mathcal{F}_m(g))=\frac{1}{2\pi}\int{dx}\left(\int{dy}_1\exp(-ixy_1)f(y_1)\right)^*\left(\int{dy}_2\exp(-ixy_2)g(y_2)\right)\tag{2} \end{equation}
\begin{equation} =\frac{1}{2\pi}\int\int{dy}_1dy_2f(y_1)^*g(y_2)\int{dx}\exp(ix(y_1-y_2))\tag{3} \end{equation}
\begin{equation} =\int\int{dy}_1dy_2f(y_1)^*g(y_2)\delta(y_1-y_2)\tag{4} \end{equation}
\begin{equation} =\int{dy_2}f(y_2)^*g(y_2)\tag{5} \end{equation}
\begin{equation} =(f,g).\tag{6} \end{equation}
My question is not about the mathematically specious introduction of the Dirac delta function, but rather what goes wrong between (2) and (3). Since $f$, $g$ $\in$ $\mathcal{S}$, all the integrals in (2) seem well defined. However, in (3) the last integral over $dx$ seems ill-defined, which suggests that passing from (2) to (3) is not justified. Since the exchange of the $x$ and $y_1$, $y_2$ integrals was the main operation performed between (2) and (3), I am guessing there is some kind of misapplication of Fubini's theorem going on. Is it the case that the conditions necessary to exchange the integrals are not met when going from (2) to (3) in the manner shown here or is something else going on?