Solution (source code)

= Solution

Grazing the equator makes it a turning point, so $\dot\theta=0$ at $\theta=\pi/2$. Conservation of <energy> gives $\frac12mv^2-mgD=h^2/(2m\ell^2)=\frac12mv^2(1-D^2/\ell^2)$. Therefore
$$
\boxed{v^2=\frac{2g\ell^2}{D}.}
$$
To check that no earlier turning point prevents reaching the equator, put $c=\cos\theta$. On $0\le c\le D/\ell$, $U(c)=h^2/[2m\ell^2(1-c^2)]-mg\ell c$ is strictly convex. Its two endpoint values are equal for this speed, so its interior values are smaller. The trajectory can therefore move between the launch point and the equator. The equator is genuinely a turning point since $dU/d\theta=mg\ell$ there.