In my lecture notes of algebraic number theory they are dealing with the polynomial $$f=X^3+X+1, $$ and they say that
If f has multiple factors modulo a prime $p > 3$, then $f$ and $f' = 3X^2+1$ have a common factor modulo this prime $p$, and this is the linear factor $f − (X/3)f'$.
Please could you help me to see why this works? And moreover, how far can this be generalized?
If polynomials $u$ and $v$ have common factors, then all of their linear combinations will have that as common factor. Now in your particular example, note that the written $f-(X/3)f'$ is already linear (hence surely irreducible), so, if there is a common factor, it must be this one.