Let
$$Z =
\begin{cases}
X, & \text{if $Y<sin^2X$} \\
X+\frac{\pi}{2}, & \text{if $Y>sin^2X$}
\end{cases}
$$
where
X ~ $U(0,\frac{\pi}{2})$ and Y ~ $U(0,1)$ are independent.
Find the PDF of $Z$.
Edit:
I'm adding my approach. I tried using CDF.
$F_Z(t)=P(Z<t)= \\ =P(X<t|Y<sin^2X)P(Y<sin^2X)+ P(X+\frac{\pi}{2}<t|Y>sin^2X)P(Y>sin^2X)= \\ =\underbrace{P(X<t,Y<sin^2X)}_L+\underbrace{P(X+\frac{\pi}{2}<t,Y>sin^2X)}_P$
$L = P(X<t,Y<sin^2X)=\iint_{\{X\in(0,t)\cup[0,\frac{\pi}{2}), Y\in(0, sin^2X)\}}f_{(X,Y)}(x,y)dxdy= \\ = \int_{x=0}^t\int_{y=0}^{sin^2x}\frac{2}{\pi}dydx=\frac{2}{\pi} \int_{x=0}^{t}sin^2xdx=\frac{2}{\pi}(\frac{x}{2}-\frac{sin2x}{4})_{0}^{t}=\frac{t}{\pi}-\frac{sin2t}{2\pi}$
$P=P(X+\frac{\pi}{2}<t,Y>sin^2X)=\iint_{\{X\in(0,t-\frac{\pi}{2})\cup[0,\frac{\pi}{2}), Y\in(sin^2X,1)\}}f_{(X,Y)}(x,y)dxdy=^{??} \\ =\int_{x=0}^{t-\frac{\pi}{2}}\int_{y=sin^{2}x}^1\frac{2}{\pi}dxdy= ...=\frac{2}{\pi}(\frac{t}{2}-\frac{\pi}{4}+\frac{sin(2t-\pi)}{4})$
$F_Z(t)=L+P=\frac{2t}{\pi}-\frac{sin2t}{2\pi}-\frac{1}{2}+\frac{sin(2t-\pi)}{2\pi}$
$f_Z(t)=F_{z}^{'}(t)=\frac{2}{\pi}-\frac{cos2t}{\pi}+\frac{cos(2t-\pi)}{\pi}=\frac{2}{\pi}-\frac{1-2sin^{2}t}{\pi}+\frac{1-2sin^{2}(t-\frac{\pi}{2})}{\pi}$
and the correct answer is $f_{Z}(z)=\frac{2sin^{2}z}{\pi}$. I think I mixed up somewhere in the integrals, but maybe the whole approach is wrong.
I'd be thankful for your support.
Trying to find the PDF by differentiating a double integral of a jpdf is causing you much confusion, I see.
There is no need to do that. Instead of taking that extra step, just find the joint pdf of $Z$ with one of the random variables, then perform one integration over appropriate bounds.
$Y$ looks promising because $Z$ is one of two linear functions of $X$ depending on how the relative value of $Y$ to $X$.
By which I mean, notice how when $Z<\tfrac \pi 2$ then $\{X=Z, Y<\sin^2(X)\}$ and when $Z>\tfrac\pi2$ then $\{X=Z-\pi/2, Y>\sin^2(X)\}$.
As such, we can express the joint pdf for $(Z,Y)$ as a piecewise function in terms of the joint pdf of $(X,Y)$ .
$\begin{align}f_{Z,Y}(z,y) &= \begin{cases} f_{X,Y}(z, y) &:& 0\leq z\lt \pi/2, 0\leq y< \sin^2(z) \\[1ex] f_{X,Y}(z{-}\pi/2, y) &:& \pi/2\leq z\leq \pi, \sin^2(z{-}\pi/2)\leq y\lt 1\\[1ex] 0&:& \text{otherwise}\end{cases}\end{align}$
Therefore, you may now find the PDF of $Z$ . $$f_Z(z) = \begin{cases} \int_?^? f_{X,Y}(?, y)\,\mathrm d y &:& 0\leq z\lt \pi/2\\[1ex] \int_?^? f_{X,Y}(?, y)\,\mathrm d y &:& \pi/2\leq z\leq \pi\\[1ex] 0 &:&\text{otherwise}\end{cases}$$