The given differential equation is:
\[
\frac{dy}{dx} + y \cot x = 2x + x^2 \cot x
\]
This is a linear first-order differential equation of the form:
\[
\frac{dy}{dx} + P(x)y = Q(x)
\]
Where \( P(x) = \cot x \) and \( Q(x) = 2x + x^2 \cot x \). The integrating factor \( \mu(x) \) is given by:
\[
\mu(x) = e^{\int P(x) \, dx} = e^{\int \cot x \, dx} = e^{\ln \sin x} = \sin x
\]
Multiply both sides of the differential equation by \( \mu(x) = \sin x \):
\[
\sin x \frac{dy}{dx} + y \sin x \cot x = (2x + x^2 \cot x) \sin x
\]
This simplifies to:
\[
\frac{d}{dx} \left( y \sin x \right) = 2x \sin x + x^2 \cos x
\]
Now, integrate both sides:
\[
\int \frac{d}{dx} \left( y \sin x \right) \, dx = \int \left( 2x \sin x + x^2 \cos x \right) \, dx
\]
The left side is:
\[
y \sin x
\]
To integrate the right-hand side, break it into two integrals:
\[
\int 2x \sin x \, dx \text{and} \int x^2 \cos x \, dx
\]
Use integration by parts for both terms.
For \( \int 2x \sin x \, dx \), we get:
\[
\int 2x \sin x \, dx = -2x \cos x + 2 \sin x
\]
For \( \int x^2 \cos x \, dx \), use integration by parts again:
\[
\int x^2 \cos x \, dx = x^2 \sin x - 2x \cos x + 2 \sin x
\]
Thus, the right-hand side becomes:
\[
-2x \cos x + 2 \sin x + x^2 \sin x - 2x \cos x + 2 \sin x = -4x \cos x + x^2 \sin x + 4 \sin x
\]
Thus, the general solution is:
\[
y \sin x = -4x \cos x + x^2 \sin x + 4 \sin x + C
\]
Now, substitute \( x = \frac{\pi}{2} \) and \( y = 0 \):
\[
0 \cdot 1 = -4 \cdot \frac{\pi}{2} \cdot 0 + \left( \frac{\pi}{2} \right)^2 \cdot 1 + 4 \cdot 1 + C
\]
Solving for \( C \):
\[
C = -4 + \frac{\pi^2}{4} + 4 = \frac{\pi^2}{4}
\]
Thus, the particular solution is:
\[
y \sin x = -4x \cos x + x^2 \sin x + 4 \sin x + \frac{\pi^2}{4}
\]
\[
y = \frac{-4x \cos x + x^2 \sin x + 4 \sin x + \frac{\pi^2}{4}}{\sin x}
\]
Final Answer:
\[
\boxed{y = \frac{-4x \cos x + x^2 \sin x + 4 \sin x + \frac{\pi^2}{4}}{\sin x}}
\]