Prove $3X^3+4X^2+3=(X+2)^2(3X+2)=(X+2)(X+4)(3X+1)$ in $\mathbb{Z}_5$.
I see that $2$ is a root (since $-24+16+3=-5$) , then $3X^3+4X^2+3=(X+2)(3X^2)$, and also $-4$ (since -$64\cdot3+16\cdot4+3=-125$) and although $x=-1/3$ is not in $\mathbb{Z}_5$, because it also works as a root then $3x+1$ is a nother factor.
Then it should be $3X^3+4X^2+3=(X+2)(X+4)(3X+1)$ but the product of the right side gives $3X^3+24X^2+30X+8=3X^3+4X^2+3+5(4X^2+6X^2+1)=3X^3+4X^2+3.$
But why is it $3X^3+4X^2+3=(X+2)^2(3X+2)$? It seems $(X+2)^2(3X+2)=(X^2+2X+4)(3X+2)=3X^4+8X^2+10X+8=3X^4+3X^2+3+5(X+2X+1)=3X^4+3X^2+3$ which is not the initial polynomial.
Also, $\mathbb{Z}_5$ is UFC domain, wouldn't the double factorization imply a contradiction?
No contradiction.
In a UFD (such as $\mathbb{Z}_5[x]$), the factorization is unique, only up to unit factors.
Note that $2$ and $3$ are units in $\mathbb{Z}_5$, hence are also units in $\mathbb{Z}_5[x]$.
Also, we have $6=1$.
Then since $$x+4 = 6x+4 = 2(3x+2)$$ and $$3x+1 = 3x + 6 = 3(x+2)$$ the factors match up, one-to-one, up to unit factors.
Another way to see it is as follows . . . \begin{align*} &(x+2)(x+4)(3x+1)\\[4pt] =\;&(x+2)(x+4)(3x+1)(6)&&\text{[since $6=1$]}\\[4pt] =\;&(x+2)\bigl(3(x+4)\bigr)\bigl(2(3x+1)\bigr)\\[4pt] =\;&(x+2)(3x+12)(6x+2)\\[4pt] =\;&(x+2)(3x+2)(x+2)&&\text{[since $12=2$ and $6=1$]}\\[4pt] =\;&(x+2)^2(3x+2)\\[4pt] \end{align*} which shows how we can convert one of the factorizations directly into the other, by multiplying the original factors by selected unit factors whose product is $1$ (e.g., by $2$ and $3$).