The problem of finding such a rearrangement of $1,\ldots, n$ can be restated in graph theory terms.
For any integer $n > 0$, consider a graph with $n$ vertices. Label the vertices
from $1$ to $n$. For any two vertex $i$ and $j$, we join them by an edge
when and only when $i + j$ is a prefect square. The problem of finding
a desired rearrangement is equivalent to finding a Hamiltonian path in such a graph.
For example, following code in maixma
load(graphs);
H[i,j] := if(integerp(sqrt(i+j))) then 1 else 0;
G(n) := from_adjacency_matrix(genmatrix(H,n,n));
hamilton_path(G(15))+1;
will return
$$[9,7,2,14,11,5,4,12,13,3,6,10,15,1,8]$$
which is essentially the rearrangement you have in reverse order.
Using codes above, I have checked for $n \le 100$, the set of $n$ that allow such
an arrangement are $15,16,17,23^{\color{blue}{[1]}}$ and all $n \ge 25$ (except for $n = 86$ where above code hangs).
As pointed out by Michael, a search on this numbers return
OEIS A090461 and $86$ is also allowed.
Notes
- $\color{blue}{[1]}$ Thanks for Michael pointing out my error on $23$.