With $y_i=x_{i+1}-x_i$ (and $y_n=x_1-x_n$), you showed that
$$\tag12f=\sum_{i=1}^n y_i^2.$$
If there is an integer $m$ with $\min x_i<m<\max x_i$, then replacing all $x_i>m$ with $x_i-1$ still leaves us with distinct integers, none of the summands in $(1)$ increases, at least two summands decrease. We conclude that in the minimal case, the $x_i$ are consecutive integers (in some order). Also, $(1)$ shows that replacing all $x_i$ with $x_i+d$ leaves $f$ unchanged. Thus we may assume that $x_1,x_2,\ldots, x_n$ is a permutation of $1,2,\ldots, n$.
Assume $(x_1,\ldots,x_n)$ is a minimizer. Pick $i,j$ with $j-i\ge 3$. Then the value of $(x_1,x_2,\ldots, x_i,x_{j-1},x_{j-2}\ldots, x_{i+1},x_j,x_{j+1},\ldots, x_n)$ (i.e., the terms between $x_i$ and $x_j$ reversed) differs from that of $(x_1,\ldots, x_n)$ by
$$ x_{j-1}x_i+x_{i+1}x_j-x_ix_{i+1}-x_{j-1}x_j=(x_{j-1}-x_{i+1})(x_i-x_j).$$
As this must be non-negative, we conclude that
$(2)$ In a minimizer, the sign of $x_{j-1}-x_{i+1}$ is the same as the sign of $x_j-x_i$ for $j\ge i+3$.
Assume that $\{x_1,\ldots x_r\}=\{1,\ldots r\}$. Assume $x_k=r+1$ with $r+1< k<n$.
Then $x_{r+1}>x_k$, hence by $(2)$, we have $r\ge x_r>x_{k+1}>r$, contradiction.
It follows that $x_{r+1}=r+1$ or $x_n=r+1$.
If additionally $x_1>x_r$ and $r<n-1$, it follows from $(2)$ that $x_{r+1}<x_n$ so that only the case $x_{r+1}=r+1$ remains.
As the sequence can be cyclically rearranged, we conclude by induction that it can be constructed as follows: Start with $1,2$, and then for $i=3,\ldots, n$, append $i$ to the end with the smaller number (which is $i-2$). Clearly, this leads to all odd numbers appended to the left of $1$ and all even numbers appended to the right of $2$.
We end up with a minimizer with $|x_{i+1}-x_i|=2$ (cyclically) for all $i$ except that $|x_{i+1}-x_i|=1$ for two $i$ (once near $1$ and once near $n$). By $(1)$, this leads to $2f=(n-2)\cdot 2^2+2\cdot 1^2$, or
$$ f=2n-3.$$