Using the basis-vectors of the inertial frame, rotational kinetic energy (assuming center of mass is fixed) is
$$ T = \tfrac{1}{2} \boldsymbol{\omega}^\intercal \boldsymbol{L} = \tfrac{1}{2} \boldsymbol{\omega}^\intercal \mathbf{I} \,\boldsymbol{\omega} $$
where $\boldsymbol{\omega}$ is the rotational velocity vector, $\boldsymbol{L}$ the angular velocity vector, and $\mathbf{I}$ the mass moment of inertia tensor. All quantities are summed about the center of mass.
Now if you know the orientation (rotational transformation) of the body $\mathrm{R}(t)$ in terms of body-to-inertial matrix, and the body-fixed mass moment of inertia matrix $\mathbf{I}_{\rm body}$ then the above is
$$ T = \tfrac{1}{2} \boldsymbol{\omega}^\intercal \left( \mathrm{R} \mathbf{I}_{\rm body} \mathrm{R}^\intercal \right) \boldsymbol{\omega} $$
Now if you know that axis of rotation in the inertial frame, then $\boldsymbol{\omega} = \omega \,\boldsymbol{\hat{n}}$
Kinetic energy is thus calculated with
$$ T = \tfrac{1}{2} \omega^2 \left( \boldsymbol{\hat{n}}^\intercal \mathrm{R} \mathbf{I}_{\rm body} \mathrm{R}^\intercal \boldsymbol{\hat{n}} \right) $$
Here the part in the parenthesis changes with time, as the orientation matrix changes. You can use Euler-Angles to encode the rotation, or use quaternions. Either way you need to calculated $\mathrm{R}$ first before doing any calculations on a rigid body.
If you know that axis of rotation in the body frame, then $\boldsymbol{\omega} = \omega \, \mathrm{R}\, \boldsymbol{\hat{n}}_{\rm body}$
Kinetic energy is thus calculated with
$$ T = \tfrac{1}{2} \omega^2 \left( \boldsymbol{\hat{n}}_{\rm body}^\intercal \mathbf{I}_{\rm body} \boldsymbol{\hat{n}}_{\rm body} \right) $$
Note that if the axis of rotation is fixed to the body, then the part in the parenthesis is a constant.
I think you are asking about the case where the axis of rotation is not fixed to the body, and KE is expressed in body-fixed coordinates (like above). In this case $ \boldsymbol{\hat{n}}_{\rm body} = \mathrm{R}^\intercal \boldsymbol{\hat{n}}$
Specifically you are using $\boldsymbol{\hat{n}} = \pmatrix{0 \\ 0 \\ 1}$ and the spherical rotation matrix
$$ \mathrm{R} = \mathrm{rot}_y(-\theta) \mathrm{rot}_z(-\phi) = \begin{pmatrix}\cos\phi\cos\theta & \sin\phi\cos\theta & -\sin\theta\\
-\sin\phi & \cos\phi & 0\\
\cos\phi\sin\theta & \sin\phi\sin\theta & \cos\theta
\end{pmatrix} $$
Note that ${\rm R}^\intercal {\rm R} = 1$ and that when the angles all are zero ${\rm R} = 1$.
Such that $$\boldsymbol{\hat{n}}_{\rm body} = {\rm R}^\intercal \boldsymbol{\hat{n}} = \begin{pmatrix}\cos\phi\sin\theta\\
\sin\phi\sin\theta\\
\cos\theta
\end{pmatrix}$$
Take the equation above and plug in the above to get
$$ T = \tfrac{1}{2} \omega^2 \left( I_1 \cos^2 \phi \sin^2 \theta + I_2 \sin^2 \phi \sin^2\theta + I_3 \cos^2 \theta \right) $$
where $I_1$, $I_2$, and $I_3$ are the three diagonal terms of the body-fixed MMOI tensor (the principal MMOI values).