The maximal value is $2\sqrt{n-1}$ if $n$ is odd, and $2\sqrt{n}$ if $n$ is even. We can prove the following:
Let $a_1, \ldots, a_n$ be real numbers, $n \ge 2$. Then
$$ \tag{*}
|a_1 - a_2| + |a_2 - a_3| + \ldots + |a_{n - 1} - a_n| + |a_n - a_1|
\le c_n \sqrt{a_1^2 + \ldots + a_n^2}
$$
where $c_n = 2\sqrt{n-1}$ if $n$ is odd, and $c_n = 2\sqrt{n}$ if $n$ is even. The bounds are sharp.
Proof: Case 1: $n$ is even. Then
$$
|a_1 - a_2| + |a_2 - a_3| + \ldots + |a_{n - 1} - a_n| + |a_n - a_1| \\
\underset{(1)}{\le} \sum_{k=1}^n (|a_k| + |a_{k+1}|) = 2 \sum_{k=1}^n (1 \cdot |a_k|)
\underset{(2)}{\le} 2 \sqrt{n} \sqrt{\sum_{i=1}^{n} a_i^2 } \, ,
$$
where the last step uses the Cauchy-Schwarz inequality.
Equality holds at $(1)$ if the $a_k$ have alternating signs, and equality holds at $(2)$ if all $|a_k|$ are equal. It follows that equality holds in $(*)$ exactly if
$$
(a_1, \ldots, a_n) = (x, -x, \ldots, x, -x)
$$
for some $x \in \Bbb R$.
Case 2: $n$ is odd. There must be (at least) one index $k$ such that $a_{k-1} - a_k$ and $a_k - a_{k+1}$ have the same sign. Without loss of generality $k=n$, so that
$$
|a_{n-1} - a_n | + |a_n - a_{1}| = |a_{n-1} - a_{1}| \, .
$$
Then, using the already proven estimate for the even number $n-1$,
$$
|a_1 - a_2| + |a_2 - a_3| + \ldots + |a_{n - 1} - a_n| + |a_n - a_1| \\
= |a_1 - a_2| + |a_2 - a_3| + \ldots + |a_{n - 1} - a_1| \\
\underset{(3)}{\le} 2\sqrt{n-1} \sqrt{\sum_{i=1}^{n-1} a_i^2 }
\underset{(4)}{\le} 2\sqrt{n-1} \sqrt{\sum_{i=1}^{n} a_i^2 } \, .
$$
Equality holds at $(3)$ if $(a_1, \ldots, a_{n-1}) = (x, -x, \ldots, x, -x)$, and equality at $(4)$ holds if $a_n = 0$. It follows that equality holds in $(*)$ exactly if
$$
(a_1, \ldots, a_n) = (x, -x, \ldots, x, -x, 0)
$$
for some $x \in \Bbb R$, or a cyclic rotation thereof.
W.L.O.G. Assume $a_{1}$ is the minimum and $a_{2}$ is the maximumm
if we have $x_{1},x_{2},...,x_{n},y_{1},y_{2},...,y_{n} \in \mathbb R $ then by cauchy-Schwars we have
$(x_{1}y_{1}+...+x_{n}y_{n})^2\leq(x_{1}^2+...+x_{n}^2)(y_{1}^2+...+y_{n}^2)$, we need an equation relating $a_{1}$ to $a_{2}$, if we put $\sqrt a_{2}, \sqrt a_{1}, \sqrt a_{3},....,\sqrt a_{n}$ in place of $x_{1},....x_{n}$ and $\frac{1}{\sqrt a_{1}},....,\frac{1}{\sqrt a_{n}}$ in place of $y_{1},...,y_{n}$ this gives $(\sqrt \frac{a_{2}}{a_{1}}+\sqrt \frac{a_{1}}{a_{2}}+n-2)^2 \leq (a_{2}+a_{1}+...+a_{n})(\frac{1}{a_{1}}+\frac{1}{a_{2}}+....+\frac{1}{a_{n}})$ combining this with the above inequality it will be much easier to proceed :) .
Best Answer
As pointed out in the comments, your solution does not work because the expression is not homogenous.
Another way to see that this reasoning is incorrect, is to extrapolate your reasoning to the case of $ \sum a_i >> n$. Specifically, consider
If your assumption about scaling is correct, then we'd say that the maximum occurs at $ a = b = 5$, with value of $ 2 \times \frac{5}{1+25} < \frac{1}{2} $. But clearly, if we had $ a = 1$, the value is at least $\frac{1}{2}$, so the $ a= b = 5$ does not achieve the maximum.
The conclusion (max occurs when all values are equal) is true when the sum is low enough.
When the sum is large, this no longer works. The reason behind that is convexity.
The second derivative of $\frac{x}{1+x^2}$ is $\frac{2x(x^2-3)}{(x^2+1)^3}$, which is positive for $x > \sqrt{3}$.
So, if $\sum a_i = An$ for $ A > \sqrt{3}$, then for $f(a_i, a_2, \ldots, a_n) = \sum_{i=1}^n \frac{a_i}{1+a_i^2}$,
$$f(A, A, \ldots , A, A) < f(A, A, \ldots, A, 2A - \sqrt{3}, \sqrt{3}) < \ldots < f( nA - (n-1)\sqrt{3}, \sqrt{3}, \sqrt{3}, \ldots , \sqrt{3}, ).$$ In fact, we can conclude that at the maximum (for any sum), at most 1 value will be $ > \sqrt{3}$ (since otherwise we can replace $a_i, a_j$ with $ \sqrt{3}, a_i + a_j - \sqrt{3} $).
Generalizing your question, we can show
One way to show this is the tangent line method:
Prove that for $ 0 < A \leq 1$ (representing $ \frac{\sum a_i}{n}$) and $ b \geq 0$, we have $$ \frac{b}{1+b^2} \leq \frac{A}{1+A^2} + \frac{1-A^2}{(1+A^2)^2} (b-A). $$ The RHS is the value of the tangent line at $ (A, \frac{A}{1+A^2})$ to $ y = \frac{x}{1+x^2}$, evaluated at $b$.
If you expand and simplify the inequality, with some work it becomes $(A-b)^2[ (A^2 - 1)b - 2A ] \leq 0$, so it's true in our given domain.
Now, summing up across $ b = a_i$, and using $ \sum a_i = nA$, we get
$$ \sum \frac{a_i}{1+a_i^2} \leq n\times \frac{A}{1+A^2} + \frac{1-A^2}{(1+A^2)^2} \sum (a_i-A) = n\times \frac{A}{1+A^2}.$$
Notes