Lemma 10.119.8 in this page on Stacks project states that a polynomial ring over a UFD is a UFD.
It uses Nagata's criterion for factoriality (10.119.7): If $A$ is a domain and $S\subset A$ a multiplicative subset generated by prime elements, and $x\in A$ is irreducible, then it's image in $S^{-1}A$ is irreducible or a unit, and $x$ is prime if and only if it's image in $S^{-1}A$ is prime or a unit.
From this, it follows that $A$ is a UFD if and only if every element of $A$ factors into irreducibles and $S^{-1}A$ is a UFD.
Now, to prove Lemma 10.119.8, $S$ is taken to be generated by all prime elements of $A$ and so $S^{-1}A$ is the field of fractions of $A$, and therefore $S^{-1}(A[X])=(S^{-1}A)[X]$ is a UFD. From this and Nagata's criterion it follows that every irreducible element of $A[X]$ is prime.
However, it still remains to show that every element of $A[X]$ factors into irreducibles, and I don't see how the proof in the link I gave addresses this point.
One approach would be to take $p(X)\in A[X]$, factor it in $(S^{-1}A)[X]$, and lift the factorization to $s\cdot p(X)=f_1(X)\cdots f_r(X)$ where $s\in S$ and the $f_i(X)$ are polynomials in $A[X]$ which are irreducible in $(S^{-1}A)[X]$. However, I don't know how to continue without getting my hands dirty with coefficients (I think that one of the points of this proof is to avoid using results like Gauss lemma, etc.).