We are given the differential equation:
\[
\frac{dy}{dx} - y \cot x = \sin 2x
\]
Step 1: Convert to standard linear form
The standard form of a first-order linear differential equation is:
\[
\frac{dy}{dx} + P(x)y = Q(x)
\]
Here, we rewrite:
\[
\frac{dy}{dx} + (-\cot x) y = \sin 2x
\]
So, \( P(x) = -\cot x \), and \( Q(x) = \sin 2x \).
Step 2: Find the Integrating Factor (I.F.)
\[
\text{I.F.} = e^{\int P(x)\, dx} = e^{\int -\cot x\, dx}
\]
\[
= e^{-\ln|\sin x|} = \frac{1}{\sin x}
\]
Step 3: Multiply the equation by the I.F.
Multiplying both sides by \( \frac{1}{\sin x} \):
\[
\frac{1}{\sin x} \cdot \frac{dy}{dx} - \frac{y \cot x}{\sin x} = \frac{\sin 2x}{\sin x}
\]
We know \( \sin 2x = 2 \sin x \cos x \), so:
\[
\frac{d}{dx} \left( \frac{y}{\sin x} \right) = 2 \cos x
\]
Step 4: Integrate both sides
\[
\int \frac{d}{dx} \left( \frac{y}{\sin x} \right) dx = \int 2 \cos x \, dx
\]
\[
\Rightarrow \frac{y}{\sin x} = 2 \sin x + C
\]
Step 5: Solve for \( y \)
\[
y = \sin x (2 \sin x + C) = 2 \sin^2 x + C \sin x
\]
Step 6: Apply the initial condition
We are given: \( y = 2 \) when \( x = \frac{\pi}{2} \).
Since \( \sin\left(\frac{\pi}{2}\right) = 1 \), we substitute:
\[
2 = 2(1)^2 + C(1) \Rightarrow 2 = 2 + C \Rightarrow C = 0
\]
Final Answer:
\[
\boxed{y = 2 \sin^2 x}
\]