Example 5 In a $1 \times n$ grid, each cell is arbitrarily filled with 1 or -1. For which $n$, can we always transform all numbers to 1 through "neighbor product transformation" (each cell is simultaneously replaced by the product of all its neighboring cells, i.e., cells sharing a common edge)?
For any sequence $\left(a_{1}, a_{2}, \cdots, a_{n}\right)$, construct a bi-infinite sequence with a period of $2(n+1)$:
$$
\cdots, a_{1}, a_{2}, \cdots, a_{2 n}, 1, a_{n}, a_{n-1}, \cdots, a_{1}, \cdots
$$

Call a certain $a_{1}$ the first cell, and the cell before the $i$-th cell is called the $(i-1)$-th cell, while the cell after the $i$-th cell is called the $(i+1)$-th cell. Let the number obtained after $i$ transformations of the $k$-th cell $a(k)$ be $a(k, i)$. Using mathematical induction, we can prove:
$$
a\left(k, 2^{j}\right)=a\left(k+2^{j}\right) a\left(k-2^{j}\right) .
$$

If for $n$, any filling of numbers can be operated to make all numbers 1, since there are only a finite number of filling methods, there must exist a number $t$ such that when the number of operations is greater than $t$, all numbers in the sequence are 1. Choose a natural number $m$ such that $2^{m}>t$. Then, for any filling of numbers, after $2^{m}$ operations, all numbers become 1. Thus, for any natural number $k$, we have $a\left(k, 2^{m}\right)=1$.
Therefore, $a\left(0, k+2^{m}\right) a\left(0, k-2^{m}\right)=1$.
Since $a(i, j)=1$ or -1,
we have $a\left(0, k+2^{m}\right)=a\left(0, k-2^{m}\right)= \pm 1$.
Let $k=k^{\prime}+2^{m}$, then
$$
a\left(0, k^{\prime}+2 \times 2^{m}\right)=a\left(0, k^{\prime}\right) \text {, }
$$

which means $a\left(0, k+2^{m+1}\right)=a(0, k)$ holds for all natural numbers $k$. Thus, the sequence $\{a(0, k)\}$ is a periodic sequence with a period of $2^{m+1}$.

By appropriately choosing $a_{1}, a_{2}, \cdots, a_{n}, a_{i}^{2}=1$, we can make the smallest period of the infinite sequence $2(n+1)$, and for a given $n$, $2(n+1)\left|2^{n+1}, n+1\right| 2^{m}$.
Therefore, $n+1=2^{r}, n=2^{r}-1$.
Conversely, when $n=2^{r}-1$, construct a similar infinite sequence such that the period of this sequence is $2 n+2=2^{r+1}$, thus,
$$
\begin{array}{l}
a(0, k)=a\left(0, k+2^{r+1}\right), \\
a\left(0, k-2^{r}\right)=a\left(0, k-2^{r}+2^{r+1}\right) \\
=a\left(0, k+2^{r}\right) .
\end{array}
$$

Therefore, $a\left(2^{r}, k\right)$
$$
\begin{array}{l}
=a\left(0, k-2^{r}\right) a\left(0, k+2^{r}\right) \\
=a\left(0, k+2^{r}\right)^{2}=1 .
\end{array}
$$

Thus, after $2^{r}$ operations, all numbers must become 1.