Where does the number 12 come from and why is it the same 12 in Wilcoxon and Kruskal Wallis? I see that it has something to do with the variance and one has 12 on the numerator and the other denominator, but why is this the same 12 and how do they become inverse?
Equations:  


*

*Kruskal Wallis: The first equation under 3 here
$$
H = \frac{12}{N(N+1)} \sum_{i=1}^g n_i\bigg(\bar r_{i\cdot}-\frac{N-1}{2} \bigg)^2
$$

*Wilcoxon: The one for the variance here
\begin{align}
z &= \frac{R - \mu_R}{\sigma_R}  \\[5pt]
&\text{where}  \\[5pt]
\mu_R &= \frac{n_1(n_1 + n_2 + 1)}{2}  \\[8pt]
\sigma_R &= \sqrt{\frac{n_1n_2(n_1 + n_2 + 1)}{12}}
\end{align}
 A: In both cases 12 appears when approximating the distribution of the test statistic with a normal and chi-square respectively because the statistic must first be written in a standardized form (if you were performing a permutation test these constants would be unnecessary). With continuous data, the ranks from $1$ to $n$ are used, and the variance of a randomly chosen value from $(1,2,3,...,n)$ is $(n^2-1)/12$.
[Consider that the expectation of a randomly chosen rank from $1$ to $n$ is $(n+1)/2$ and the expected value of the square of a randomly chosen rank is $n(n+1)(2n+1)/(6n)$; the variance of a randomly chosen rank is therefore $(n+1)(n-1)/12$. Similarly, the covariance of two randomly selected values (chosen without replacement) from $(1,2,3,...,n)$ is $-(n+1)/12$.]
As a result the variance of either the sum or the average of $m$ randomly chosen ranks from $(1,2,3,...,n)$ will have $12$ in it.

There's no "inversion" of the 12 differently in either formula - in both cases there's a denominator term involving a function of (something/12). If you divide by something/12 that's the same as multiplying by 12/something. So in the Kruskal-Wallis we see it simplified to be written that "12/something" way. In the Wilcoxon rank sum test when you're using the normal approximation you divide by the square root of the variance, so there's a $\sqrt{}$(something/12) in the denominator; it could as easily be written as $\times \sqrt{}$(12/something).
For similar reasons (at heart, because an expected squared rank involves $\sum_{i=1}^n i^2$), either 12 or 6 (or sometimes a 24) appears in formulas related to many other rank-based statistics.
