Why is the 2nd derivative written as $\frac{\mathrm d^2y}{\mathrm dx^2}$? In Leibniz notation, the 2nd derivative is written as
$$\dfrac{\mathrm d^2y}{\mathrm dx^2}\ ?$$
Why is the location of the $2$ in different places in the $\mathrm dy/\mathrm dx$ terms?
 A: The $d$ is meant to represent the "change in". And the Leibniz notation is meant to remind you that you are computing the ratio between the change in $y$ and the change in $x$. 
When you take the second derivative, you are computing how the derivative is changing as $x$ changes; that is, you are trying to compute
$$\frac{d(y')}{dx}.$$
Now, $y'$ is itself a rate of change: it is the rate at which $y$ changes. So the "numerator" of the differential notation is telling you that you are trying to consider the change in the change in $y$, not the change in $y^2$ (which is what "$dy^2$" would represent).
So you are trying to describe the change in "the-change-in-$y$", relative to how $x$ is changing. $x$ is only changing "once", so you should have a single $d$ in the "denominator" (remember, not really a denominator). So why $x^2$? Because you are trying to figure out the change of blah as $x$ changes, and blah is a rate of change as $x$ changes as well. So you are taking $x$ twice, but considering only one change. Hence, single $d$, but $x$ squared.
A: There is no possible way of understanding why Leibniz invented the notation he did unless you think about calculus the way Leibniz did, using infinitesimal numbers.
Take the velocity $dx/dt$. Leibniz would have described it as the ratio of two infinitesimals. (Nonstandard analysis shows that this idea can be made rigorous, but in any case limits didn't exist in Leibniz's time.) The numerator is an infinitesimal number with units of meters. The denominator is an infinitesimal with units of seconds. You divide them, and it gives m/s.
In the acceleration, $d^2x/dt^2$, the numerator is written to suggest something with units of meters, and the denominator to suggest units of seconds squared, giving the correct units of m/s$^2$.
A: Purely symbolically, if we accept that $dy = f'(x)\,dx$, and treat $dx$ as a constant, then $$d^2y = d(dy) = d(f'(x)\,dx) = dx\,d(f'(x)) = dx\,f''(x)\,dx = f''(x)\,(dx)^2,$$
so dividing yields:
$$\frac{d^2y}{(dx)^2} = \frac{d^2y}{dx^2} = f''(x).$$
As to where this notation actually comes from, though: My guess is that it comes from a time when mathematicians primarily thought of $dx$ and $dy$ as "infinitesimal quantities."  There are ways of doing so rigorously (via non-standard analysis), and perhaps there is a way of making this notation rigorous that way.

However, we can still give rigorous meaning to these calculations without appealing to non-standard analysis by using the language of bilinear forms.
If $f$ is differentiable, we can define a map
\begin{align*}
df\colon \mathbb{R} & \to L(\mathbb{R}; \mathbb{R}) \\
df(x)(dx) & = f'(x)\,dx.
\end{align*}
Here, $L(\mathbb{R};\mathbb{R})$ denotes the set of linear maps from $\mathbb{R} \to \mathbb{R}$, and $dx$ is simply a real number.  Going one step further, we can consider the map $$d^2f = d(df)\colon \mathbb{R} \to L(\mathbb{R};L(\mathbb{R};\mathbb{R})).$$
By identifying $L(\mathbb{R}; L(\mathbb{R}; \mathbb{R}))$ with the set of bilinear maps $B(\mathbb{R} \times \mathbb{R};\mathbb{R})$, we have the  bilinear map
$$d^2f(x)(dx^1, dx^2) = dx^1\, f''(x) \,dx^2$$ whose associated quadratic form is $$d^2f(x)(dx) = f''(x)\,(dx)^2.$$
It is now perfectly legal to divide on both sides by $(dx)^2$, obtaining $$\frac{d^2f}{dx^2} = f''(x).$$
A: Somewhat mundanely,
$$ \frac{d}{dx}\left(\frac{d}{dx}(y)\right) = \frac{d}{dx}\left(\frac{dy}{dx}\right) = \frac{d\,dy}{dx\,dx} = \frac{d^2 y}{dx^2} $$
A: Glossing over a few issues for clarity,
If I wanted you to differentiate, say $3x^4$ twice, I could ask the question in a variety of ways such as, 
1) Find the second derivative of $3x^4$
2) If $f(x)=3x^4$, find $f''(x)$
3) If $y=3x^4$ find $\frac{d^2y}{dx^2}$
The latter is an accepted lazy corruption of the more technically correct,
Find,
$$ \big(\frac{d}{dx}\big)^2 y$$
or find
$$ \big(\frac{d}{dx}\big)^2 (3x^4)$$
So, essentially, you have spotted that mathematicians are quite lazy, when they can get away with it !
Although we write $\frac{d}{dx}$ this isn't a fraction in the sense that $\frac{2}{5}$ is. Perhaps best to park that thought for now, although maybe 'expanding the brackets' of $\big(\frac{d}{dx}\big)^2$ as $\frac{d^2}{dx^2}$ rather than $\frac{d^2}{(dx)^2}$ is a reminder of that.
All of this does makes it harder for beginners to make sense of the notation. There are many, many more examples I could give of such 'lazy corruption'. I think of it as being like learning any foreign language, where there are always all sorts of quirks and customs that break a general rule.
Once you understand the 'lazy corruption' in the context of its surroundings, the meaning is, more often than not, actually, perfectly clear. 
This answer was given when this question was asked again, in March 2019 here : Why $x^2$ in $\frac{d^2y}{dx^2}$?
A: Leibniz notation is probably the most common notation for the derivative, but it is just a notation: there is no objective derivation for the notation itself, and alternatives exist such as Euler notation ($D_x^2 y$). In fact, if we wanted to derive the Leibniz notation for the second derivative in a more systematic way, we could use the quotient rule on the first derivative:
$$
\frac{\mathrm d\left( \frac{\mathrm d y}{\mathrm d x} \right)}{\mathrm d x}
= \frac{ \frac{\mathrm d^2 y}{\mathrm d x} - \frac{\mathrm d y}{\mathrm d x} \frac{\mathrm d^2 x}{\mathrm d x} }{\mathrm d x}
= \frac{\mathrm d^2 y}{\mathrm d x^2} - \frac{\mathrm d y}{\mathrm d x}\frac{\mathrm d^2 x}{\mathrm d x^2}
$$
Now we have a notation that we can algebraically manipulate to derive identities to, e.g., swap dependent and independent variable:
$$
- D_x^2 y \left( \frac 1 {D_xy} \right)^3 = D_y^2x
$$
Using a system where differentials are algebraically manipulable highlights the importance of the distinction between $\mathrm d^2 x = \mathrm d(\mathrm d(x))$ and $\mathrm d x^2 = (\mathrm d(x))^2$.  To see this hands-on, attempt to prove (4) via algebraic manipulation.
It's much harder to understand intuitively what $\mathrm d^2 t/\mathrm d t^2$  means in this new system but, crucially, it's not the derivative of $\mathrm d t / \mathrm d t$.
