The $n^2(n^2-1)/12$ comes from the symmetries of the Riemann tensor and the algebraic Bianchi identity.
$R_{abcd}$ is antisymmetric in $ab$ and in $cd$. This means that these pairs of indices can take
$$m=\binom{n}{2}=\frac{n(n-1)}{2}$$
different values. For example, for $n=4$, they take the values $01,02,03,12,13,23$; for other values like $11$, the component is zero.
$R_{abcd}$ is also symmetric when you swap $ab$ with $cd$. This means that, if we didn't take the algebraic Bianchi identity into account, there would be
$$\frac{m(m+1)}{2}=\frac{n^4-2n^3+3n^2-2n}{8}$$
independent components. For $n=4$, there are 21 of them:
$$0101, 0102, 0103, 0112, 0113, 0123$$
$$0202, 0203, 0212, 0213, 0223$$
$$0303, 0312, 0313, 0323$$
$$1212, 1213, 1223$$
$$1313, 1323$$
$$2323$$
Finally, the algebraic Bianchi identity,
$$R_{abcd}+R_{acdb}+R_{adbc}=0$$
provides
$$\binom{n}{4}=\frac{n^4-6n^3+11n^2-6n}{24}$$
relationships between these components. (In this identity, the indices must be all different; otherwise, it reduces to the previous symmetry and antisymmetry relations. So we're choosing 4 indices out of $n$.) Subtracting off this number reduces the number of independent components to
$$\frac{n^4-2n^3+3n^2-2n}{8}-\frac{n^4-6n^3+11n^2-6n}{24}=\frac{n^4-n^2}{12}=\frac{n^2(n^2-1)}{12}.$$
Summarizing this argument, the number of independent components is
$$\frac{1}{2}\binom{n}{2}\left[\binom{n}{2}+1\right]-\binom{n}{4}=\frac{n^2(n^2-1)}{12}.$$
Here is a table of the number of independent components of the Riemann tensor for various dimensions up to 26, the maximum that I think physicists care about:
$$\begin{array}{cc}
1 & 0 \\
2 & 1 \\
3 & 6 \\
4 & 20 \\
5 & 50 \\
6 & 105 \\
7 & 196 \\
8 & 336 \\
9 & 540 \\
10 & 825 \\
11 & 1210 \\
12 & 1716 \\
13 & 2366 \\
14 & 3185 \\
15 & 4200 \\
16 & 5440 \\
17 & 6936 \\
18 & 8721 \\
19 & 10830 \\
20 & 13300 \\
21 & 16170 \\
22 & 19481 \\
23 & 23276 \\
24 & 27600 \\
25 & 32500 \\
26 & 38025 \\
\end{array}$$
Best Answer
The fact that a function's first derivative vanishes at a point does not mean that its second derivative vanishes at that point. Note that for $f(x)=x^2$, $f'(0)=0$ but $f''(0)=2$.