First, let's find a boundary function of the form
$$ w(x,t) = 2\pi t \big(Ax^2 + Bx + C\big) $$
such that $w_x(0,t) = 0$ and $w_x(\pi,t) = 2\pi t$. Solving this you'll find $B=0$ and $A=\frac{1}{2\pi}$, giving $w(x,t) = tx^2$ ($C$ is free here, but for simplicity we can let it be $0$).
Now let $u(x,t) = tx^2 + v(x,t)$, then $v(x,t)$ solves the Neumann problem
\begin{cases} v_{tt} - v_{xx} = \cos(2t)\cos(3x) \\
v_x(0,t) = v_x(\pi,t) = 0 \\
v(x,0) = \cos^2 x \\
v_t(x,0) = 1 \end{cases}
The eigenfunctions in the $x$-direction that satisfies Neumann B.C.s are $X_n(x) = \cos(nx)$, so we look for a solution of the form
$$ v(x,t) = T_0(t) + \sum_{n=1}^\infty T_n(t)\cos(nx) $$
Plugging this form into the PDE for $v$
$$ T_0''(t) + \sum_{n=1}^\infty \big[T_n''(t) + n^2T_n(t)\big]\cos(nx) = \cos(2t)\cos(3x) $$
$$ \implies \begin{cases} T_0''(t) = 0 \\ T_3''(t) + 9T_3(t) = \cos 2t \\ T_n''(t) + n^2T_n(t) = 0, && n \ne 0, 3 \end{cases} $$
The initial conditions are given by
\begin{align}
u(x,0) &= T_0(0) + \sum_{n=1}^\infty T_n(0)\cos(nx) = \cos^2 x = \frac12 + \frac12\cos 2x \\
u_t(x,0) &= T_0'(0) + \sum_{n=1}^\infty T_n'(0)\cos(nx) = 1
\end{align}
$$ \implies \begin{cases} T_0(0) = \frac12, T_0'(0) = 1 \\ T_2(0) = \frac12, T_2'(0) = 0 \\ T_n(0) = T_n'(0) = 0, && n \ne 0, 2 \end{cases} $$
Solving the above IVPs we have
\begin{cases} T_0(t) = \frac12 + t \\ T_2(t) = \frac12\cos(2t) \\ T_3(t) = \frac15\cos(2t) - \frac15 \cos(3t) \\ T_n(t) = 0, && n \ne 0,2,3 \end{cases}
Putting everything together
$$ u(x,t) = tx^2 + \frac12 + t + \frac12\cos(2t)\cos(2x) + \frac15 \big(\cos(2t)-\cos(3t)\big)\cos(3x) $$