Step 1: Identify the type of differential equation.
The given differential equation is
\[
x\frac{dy}{dx}=y-x\sin^2\left(\frac{y}{x}\right)
\]
Divide both sides by \(x\):
\[
\frac{dy}{dx}=\frac{y}{x}-\sin^2\left(\frac{y}{x}\right)
\]
Since the equation contains the ratio \(\frac{y}{x}\), it is a homogeneous differential equation.
Step 2: Use substitution.
Let
\[
v=\frac{y}{x}
\]
Thus
\[
y=vx
\]
Differentiate both sides:
\[
\frac{dy}{dx}=v+x\frac{dv}{dx}
\]
Step 3: Substitute into the equation.
\[
v+x\frac{dv}{dx}=v-\sin^2 v
\]
Cancel \(v\) from both sides:
\[
x\frac{dv}{dx}=-\sin^2 v
\]
Step 4: Separate variables.
\[
\frac{dv}{\sin^2 v}=-\frac{dx}{x}
\]
Step 5: Integrate both sides.
Recall the identity
\[
\frac{1}{\sin^2 v}=\csc^2 v
\]
Thus
\[
\int \csc^2 v\,dv=-\int \frac{dx}{x}
\]
\[
-\cot v=-\ln|x|+C
\]
Multiply by \(-1\):
\[
\cot v=\ln|x|+C
\]
Step 6: Substitute back $v=\frac{y{x}$.}
\[
\cot\left(\frac{y}{x}\right)=\ln|x|+C
\]
Step 7: Use the initial condition.
Given
\[
y(1)=\frac{\pi}{6}
\]
Thus
\[
\frac{y}{x}=\frac{\pi}{6}
\]
Substitute \(x=1\):
\[
\cot\left(\frac{\pi}{6}\right)=\ln1+C
\]
\[
\sqrt3=0+C
\]
\[
C=\sqrt3
\]
Step 8: Write the final solution.
\[
\cot\left(\frac{y}{x}\right)=\ln|x|+\sqrt3
\]
Final Answer:
\[
\boxed{\cot\left(\frac{y}{x}\right)=\ln|x|+\sqrt3}
\]