The argument in question is not a rearrangement but a selection of Fourier coefficients.
Let's first recall some relevant preliminaries. A reference is Einsiedler & Ward's Ergodic Theory, with a view towards Number Theory, Appendix C.3: Pontryagin Duality (pp. 433-440).
Let $G$ be an LCH abelian group. Then the group $\widehat{G}$ of topological group homomorphisms $\chi: G\to S^1 = \{z\in \mathbb{C}||z|=1\}$ endowed with the compact-open topology (= topology of uniform convergence on compact subsets) itself is an LCH abelian group and members of $\widehat{G}$ are called characters of $G$. Let us denote by $\langle\cdot|\cdot\rangle$ the natural bilinear pairing $\widehat{G}\times G\to S^1$.
If $G$ is compact abelian, then $\widehat{G}$ is countable discrete. Further, any Haar measure $dg$ on $G$ is unimodular and finite, so we may as well take it to be a probability measure. Let us consider $\widehat{G}$ with counting measure.
The Fourier transform on $L^2(G,\mathbb{C})$ acts like so:
$$f \mapsto \left[\hat{f}: \widehat{G}\to \mathbb{C},\; \chi \mapsto \int_G f(\chi) \overline{\langle \chi | g\rangle} dg \right].$$
The crucial theorem is this:
Theorem: For any compact abelian group $G$, $\widehat{G}$ is a complete orthonormal basis of $L^2(G,\mathbb{C})$.
This means that for computational purposes:
- $\forall f\in L^2(G,\mathbb{C}): f(g) = \sum_{\chi\in\widehat{G}}\hat{f}(\chi)\langle\chi|g\rangle$ for almost every $g\in G$.
- $\forall f_1,f_2\in L^2(G,\mathbb{C}), \forall \chi\in \widehat{G}: \hat{f_1}(\chi)=\hat{f_2}(\chi) \implies f_1(g)= f_2(g)$ for almost every $g\in G$ (and vice versa, of course).
Now let $G$ be compact abelian, $T: G\to G$ be a topological group homomorphism. Pullback by $T$ (the Koopman operator in ergodic theory cycles)
$$U_T: f \mapsto f\circ T$$
acts unitarily on $L^2(G,\mathbb{C})$ and $\widehat{G}$.
If $T$ is onto (= right-cancellable), then it preserves $dg$ (see Endomorphisms preserve Haar measure or Surjective endomorphism preserves Haar measure). Further, $U_T$ is injective (= left-cancellable). In particular we have a bijection
$$U_T : \widehat{G} \to U_T\left(\widehat{G}\right).$$
(This is what I meant by "selection" above.)
Let $f\in L^2(G,\mathbb{C})$ be $T$-invariant (i.e. $U_T$-invariant), so that $f=U_T(f)=f\circ T$ (almost everywhere). The Fourier expansion of $f$ at a generic point $g$ gives:
$$f(g) = \sum_{\chi\in\widehat{G}}\hat{f}(\chi)\langle\chi|g\rangle = \sum_{\chi\in U_T\left(\widehat{G}\right)}\hat{f}(\chi)\langle\chi|g\rangle + \sum_{\chi\in \widehat{G}\setminus U_T\left( \widehat{G}\right)}\hat{f}(\chi)\langle\chi|g\rangle.$$
Since $T$ is measure preserving $T(g)$ is also a generic point (of course one could be more rigorous here), and the Fourier expansion of $f$ at $T(g)$ gives:
$$f(T(g)) = \sum_{\rho\in\widehat{G}}\hat{f}(\rho)\langle\rho|T(g)\rangle = \sum_{\rho\in\widehat{G}}\hat{f}(\rho)\langle U_T(\rho)|g\rangle.$$
Here in the orthonormal basis $\widehat{G}$ the only characters we are using are the ones included in $U_T\left(\widehat{G}\right)$. Doing a change of variables $\chi = U_T(\rho)$, which we can for $\rho\in U_T\left(\widehat{G}\right)$ unambiguously, we get
$$f(T(g)) = \sum_{\chi\in U_T\left(\widehat{G}\right)}\hat{f}\left(U_T^{-1}(\chi)\right)\langle \chi|g\rangle = \sum_{\chi\in U_T\left(\widehat{G}\right)}\hat{f}\left(U_T^{-1}(\chi)\right)\langle \chi|g\rangle + \sum_{\chi\in \widehat{G}\setminus U_T\left( \widehat{G}\right)}0\;\langle\chi|g\rangle.$$
Comparing this with the Fourier expansion of $f$ at $g$ (which we can by the theorem), we have that
$$\forall \chi \in \widehat{G}: \hat{f}(\chi) = \begin{cases} 0,& \text{ if } \chi \in \widehat{G}\setminus U_T\left( \widehat{G}\right)\\
\hat{f}\left(U_T^{-1}(\chi)\right),& \text{ if } \chi \in U_T\left( \widehat{G}\right)\end{cases}
$$
Reusing the change of variables $\chi = U_T(\rho)$ in tandem with the second row, we have:
$$\forall \rho\in \widehat{G}: \hat{f}(U_T(\rho)) = \hat{f}(\rho).$$
Thus $\hat{f}\circ U_T = \hat{f}$.
Finally let me remark that doing these calculations for $G=\mathbb{T}$ and $T$ an irrational rotation or multiplication by some positive integer is very instructive.