This boils down to the uniqueness of the set of roots of a (quadratic) polynomial (which holds true in a commutative ring $R\iff R$ is an integral domain, i.e. $\,xy = 0\Rightarrow x=0\,$ or $\,y=0)$
Lemma $\ $ TFAE for $\,A,B,a,b\in \Bbb Q\,$ (or $\Bbb R$ or $\Bbb C$ or any integral domain)
$(1)\quad A+B = a+b,\,\ AB = ab,\ $ i.e. $\,\{A,B\}\ \&\ \{a,b\}\,$ have equal sum & product
$(2)\quad (X\!-\!A)(X\!-\!B) = (X\!-\!a)(X\!-\!b),\ $ i.e. equal polynomials in $X$, i.e. equal coef's
$(3)\quad \{A,B\} = \{a,b\},\ \ $ i.e, equal multi-sets
Proof $\ (1\!\Rightarrow\! 2)\ $ Expanding both polynomials shows they have equal coef's, after applying $(1)$.
$(2\!\Rightarrow\! 3)\ $ Eval $(2)$ at $X = A\Rightarrow (A-a)(A-b) = 0\,$ so, since $D$ is a domain, $A = a\,$ or $A = b.\,$ Wlog $A = a,\,$ so eval $(2)$ at $\,X = a+1\Rightarrow X-B = X-b,\,$ so $\,B = b$.
$(3\!\Rightarrow\! 1)\ $ Equal multi-sets have equal sum & product (since both operations are commutative)
Remark $ $ Generally if fails in non-domains (rings with zero-divisors) since if $\,ab=0,\,\ a,b\ne 0\,$ then $\, (X\!-\!a)(X\!-\!b) = X(X\!-\!a\!-\!b)$ and $\{a,b\}\ne \{0,a+b\}.\,$ So the equalities in the Lemma are equivalent for a ring iff the ring is an integral domain, i.e. it has no zero-divisors, i.e. all elements $\ne 0$ are cancellable. Another way to view it is that $D$ is a domain iff $\,X\!-\!a\,$ is prime in $\,D[X],\,$ and the the uniqueness of the root sets corresponds to the uniqueness of the associated prime factorization $\,(X\!-\!a)(X\!-\!b),\,$ see here. More generally we can use the uniqueness of linear factorizations $f = (X-a_1)\cdots (X-a_n)\,g,\,$ where $g$ has not roots.