To show that a ring is a PID it suffices to show that it is Euclidean. On $\mathbb Z[\sqrt{2}]$ we have the norm $N(a+b\sqrt{2}) = |a^2-2b^2|$ which we can extend to $\mathbb Q(\sqrt{2})$, the quotient field of $\mathbb Z[\sqrt 2]$. First note that for each element $x \in \mathbb Q(\sqrt 2)$ we find an element $\tilde x \in \mathbb Z[\sqrt 2]$ with $N(x-\tilde x) < 1$. Namely, if $x = a + b\sqrt 2$, let $\tilde a$ and $\tilde b$ the nearest integer to $a$ and $b$ respectively and let $\tilde x = \tilde a + \tilde b \sqrt 2$. Then $$N(x-\tilde x) = |(a-\tilde a)^2 -2(b-\tilde b)^2| \leq \left(\frac{1}{2}\right)^2 + 2\left(\frac{1}{2}\right)^2 = \frac{3}{4} < 1.$$
Now let $x$ and $y$ be elements of $\mathbb Z[\sqrt 2]$ with $y \neq 0$. We have to show that there exist $k$ and $r \in \mathbb Z[\sqrt2]$ such that $x = ky+r$ and $N(r)< N(y)$. Choose $k \in \mathbb Z[\sqrt 2]$ with $N(x/y - k) < 1$ and let $r = x-ky$. Then $x = ky+r$ and $$N(r) = N(x-ky) = N(y) N(x/y-k) < N(y).$$
This shows that $\mathbb Z[\sqrt 2]$ is Euclidean, hence it is a PID.
As stated your question is too general for us to have an answer - it's an open problem, but from what you said after that I think you meant to ask this more specific question instead: for negative integers $d$, when is the ring of integers of $\mathbb{Q}(\sqrt{d})$ a PID? To that we have an answer but the proof is highly non-trivial.
First note that this ring of integers is $\mathbb{Z}[\omega]$ where $\omega=\frac{1+\sqrt{d}}{2}$ if $d\equiv 1 \bmod 4$, and $\omega=\sqrt{d}$ if $d\equiv 2,3 \bmod 4$.
Then, due to Stark, 1966, we know that $\mathcal{O}_d$ is a PID $\iff d=$-1, -2 , -3 , -7, -11, -19, -43, -67, or -163.
Stark's proof is hard. But it is easier in the cases where you can show it's a PID by showing it's a Euclidian domain, which (for $d< 0$) is true $\iff d=-1,-2,-3,-7,$ or $-11$. Getting that part has to do with using the field norm and doing a lot of arithmetic. You should be able to find it in textbooks.
Best Answer
This is a classical example. Here are a few references (out of many) which give a detailed proof.
1.) An example of a PID that is not a Euclidean Domain.
2.) A principal ideal domain that is not Euclidean.
3.) On a Principal Ideal Domain that is not a Euclidean Domain.
4.) Ring of integers is a PID but not a Euclidean domain.
5.) An example of a PID that is not a Euclidean Domain.