Why is quadratic integer ring defined in that way? Quadratic integer ring $\mathcal{O}$ is defined by
\begin{equation}
   \mathcal{O}=\begin{cases}
      \mathbb{Z}[\sqrt{D}] & \text{if}\ D\equiv2,3\ \pmod 4\\
      \mathbb{Z}\left[\frac{1+\sqrt{D}}{2}\right]\  & \text{if}\ D\equiv1\pmod 4
   \end{cases}
\end{equation}
where $D$ is square-free.
I understand $\mathbb{Z}\left[\frac{1+\sqrt{D}}{2}\right]$ is not closed under multiplication if $D\equiv2,3\pmod 4$. But still, isn't it more natural to define $\mathcal{O}=\mathbb{Z}[\sqrt{D}]$ for all square-free $D$? (In that case, it really seems like 'quadratic integer'.) I wonder what is the motivation of this definition.

Have you studied norms yet? If $x$ is an algebraic number in a given quadratic domain such that the leading coefficient of its minimal polynomial is 1, then its norm in that domain is an integer from $\mathbb{Z}$ and $x$ is called an algebraic integer.
Consider these two numbers: $$\frac{1}{2} + \frac{\sqrt{-7}}{2}$$ and $$\frac{1}{2} + \frac{\sqrt{7}}{2}.$$ The former is an algebraic number in $\mathbb{Q}(\sqrt{-7})$, the latter is an algebraic number in $\mathbb{Q}(\sqrt{7})$. Both are algebraic numbers, but only one of them is an algebraic integer. Observe that $$N\left(\frac{1}{2} + \frac{\sqrt{-7}}{2}\right) = \left(\frac{1}{2} - \frac{\sqrt{-7}}{2}\right)\left( \frac{1}{2} + \frac{\sqrt{-7}}{2}\right) = 2$$ but $$N\left(\frac{1}{2} + \frac{\sqrt{7}}{2}\right) = \left(\frac{1}{2} - \frac{\sqrt{7}}{2}\right)\left( \frac{1}{2} + \frac{\sqrt{7}}{2}\right) = -\frac{3}{2}.$$
We should have seen that coming because $-7 \equiv 1 \pmod 4$ but $7 \equiv 3 \pmod 4$. If $D \not\equiv 1 \pmod 4$, then only numbers of the form $a + b\sqrt{D}$ with $a, b \in \mathbb{Z}$ have $N(a + b\sqrt{D}) \in \mathbb{Z}$. But if $D \equiv 1 \pmod 4$, then it's also possible for numbers of the form $\frac{a}{2} + \frac{b\sqrt{D}}{2}$ to have integer norm, provided $a$ and $b$ have the same parity.
No number of another form in $\mathbb{Q}(\sqrt{D})$ can have integer norm. For example, $$N\left(2 + \frac{\sqrt{-7}}{2}\right) = \left(2 - \frac{\sqrt{-7}}{2}\right)\left( 2 + \frac{\sqrt{-7}}{2}\right) = \frac{23}{4}.$$ I've seen short but dense proofs of this in a couple of different books.
