One way to see that is that $x=3$ is a root of $x^3 - 12x + 9$. So $(x-3)$ will be a factor (by the Factor Theorem).
Now you can try to get $x-3$ somehow.
One way you can do that is to rewrite
$$x^3-12x + 9 = x^3 - (3^3 - 3^3) - 12(x - 3+3) + 9$$
$$ = x^3 - 27 + 27 - 12(x - 3) - 36 + 9 = x^3 - 27 - 12(x-3) + (9 -36 + 27)$$
$$ = (x-3)(x^2+3x+9) - 12(x-3) = (x-3)(x^2+3x-3) $$
Here we used the fact that $x^3 - a^3 = (x-a)(x^2 + ax + a^2)$
In general, if $r$ is a root of $f(x) = a_{n}x^n + a_{n-1}x^{n-1} + \dots + a_{0}$, then $f(x) - f(r) = f(x)$ gives us a way to factorize $f(x)$ as $(x-r)g(x)$.
$$f(x) = a_{n}x^n + a_{n-1}x^{n-1} + \dots + a_{0} - (a_{n}r^{n} + a_{n-1}r^{n-1} + \dots +a_{0})$$
$$ = a_{n}(x^n - r^n) + a_{n-1}(x^{n-1} - r^{n-1}) + \dots + a_{1}(x-r)$$
Just like $x^3 - a^2 = (x-a)(x^2 + ax + a^2)$ we have that
$$x^n - r^n = (x-r)(x^{n-1} + rx^{n-1} + \dots + r^{n-1})$$
and so
$$f(x) = (x-r) (a_{n}(x^{n-1} + rx^{n-2} + \dots + r^{n-1}) + a_{n-1}(x^{n-2} + \dots +r^{n-1}) + \dots + a_1)$$
Once we know a root, we can also try using Polynomial Long Division to get the other factor.
For cubics, the roots can be found without the need to guess. Check this out: Cardano's Method.
Does that help?