We want to make P = xy^2 into something more complicated, which only has Xs, and no Ys.
Firstly, you need to remember that when there are two equations, the question will almost definitely involve substituting one into the other. In this question, it happens to be that that's all there is to it.
By making y the subject of one equation, we can eliminate it from another. In this case we want P = [complicated thing with no x], so we make y the subject of the other equation, to eliminate it from this one.
Making y the subject: 2x + y = 12 ----> y = 12-2x
Substitute that into P = xy^2: P = x(12-2x)^2
Expand = x(144 + 4x^2 - 48x)
= 4x^3 - 48x^2 + 144x