I'm going to present a justification for the choice of the particular solution and its relation with the input function $g(x)$ - RHS; and then I'm going to discuss the case you provided.
Note that the general method of undetermined coefficients is limited to nonhomogeneous linear DE with constant coefficients.
Since the input function $g(x)$ results from applying the polynomial differential operator $L$ to the particular solution $y_p$; it's reasonable for the input function to equal a linear combination consisting of $y_p$ and its derivatives---by a linear combination I mean multiplying each term by a constant and adding the results.
This is possible because the coefficients of the DE are constants.
The method is exclusive for the cases where $g(x)$ is a polynomial, an exponential, a sine, a cosine or an arithmetic combination of them by means of addition, substraction or/and multiplication.
The DE you provided is with noncostant coefficients, it would be wrong to apply the method of undetermined coefficients in this case.
However, as a counter-example let's try to use the method here.
$$(x + 1)y'' + xy' - y = x^2 + 2x + 1.$$
According to the method we assume:
$$y_p = Ax^2 + Bx + C,$$ so we have $y_p' = 2Ax + B$ and $y_p'' = 2A$.
We substitute them into the DE to obtain:
$$(x + 1)\cdot 2A + x(2Ax + B) - Ax^2 - Bx - C = x^2 + 2x + 1,$$
$$Ax^2 + 2Ax + (2A - C)= x^2 + 2x + 1.$$
As you can see, when we compare the coefficients of $x$ on both sides to figure out the values of $A, B$ and $C$; we find that $B$ is dropped in the LHS and we can never find its value.
**Note the difference between my substitution and yours: I used $A$ instead of $c$ and $C$ instead of $a$, it's a matter of habit of course.
I couldn't fully understand your last sentence.
If you are dissatisfied with the process of assuming the coefficients and comparing LHS with RHS to find their values, you can use the method of variation of parameters. However, variation of parameters requires that you know the complementary function $y_c$ first.
Because the coefficients of the given equation are noncostant, you need to use some substitution or the Laplace Transform in order to solve the associated homogeneous DE.
I hope my answer sheds some light on your problem.