The problem is equivalent to finding $\min_{e_i, \lambda} \sum (w(e_i) - \lambda)^2$, where $\lambda$ is a free real parameter subject to optimization as well as the edges of a spanning tree. Indeed, for a chosen set of edges $e_i$ we have that $\sum (w(e_i) - \lambda)^2$ is minimized when $\lambda$ is the mean of $w(e_i)$.

If $\lambda$ is fixed, we can use, say, Kruskal's algorithm which considers edges by increasing of $|w(e) - \lambda|$. Note that if we gradually increase $\lambda$, the order of edges only changes at $\lambda = (w(e) + w(e')) / 2$ for some edges $e, e'$, therefore there are polynomially many different orders. Run Kruskal's algorithm with respect to each of these orders and choose the best answer.

The complexity is roughly $O(|E|^3)$ if done straightforwardly. **UPD**: This approach can be optimized to $O(|E|^2 \log |V|)$, roughly as follows: when we process a "two edges $e_1$, $e_2$ switch their order to $e_2$, $e_1$" event, the result of the Kruskal algorithm changes iff all edges on the cycle of the current MST induced by $e_2$ are $\geq e_1$, then we have to delete $e_1$ and insert $e_2$. This can be done efficiently with link-cut trees.

UPD" : according to p. 9 in Naoki Katoh:An ϵ-approximation Scheme for Minimum Variance Combinatorial Problems. International Institute for Applied Systems Analysis Austria. WP-97-117, 1987, theminimum-variance spanning tree[ed.: this is the key technical term] can be solved in time $O(h(V,E)\cdot\lvert V\rvert\cdot\lvert E\rvert)$, where $h(V,E)$ denotes the # of steps required for finding an MST in $G=(V,E)$; and it's known that $h(V,E)\in O(\lvert E\rvert\cdot\min\{ i\in\omega\mid\ i>0,\log^{\circ i}(n)\leq\lvert E\rvert/\lvert V\rvert\})$. $\endgroup$2more comments