Can the derivative of the distance function from a subset be zero? Let $M$ be a smooth Riemannian manifold, and let $S \subseteq M$ be compact. Let $d_S$ be the distance function from $S$. Let $p \in M \setminus{S}$, and suppose that $d_S$ is differentiable at $p$. Is it possible that $d(d_S)_p=0$? (can $p$ be a critical point of $d_S$?)

If there exist a length-minimizing path from $p$ to $S$, then $d(d_S)_p\neq 0$. What happens when such a length-minimizing path does not exist?

Indeed, if $\alpha(t)$ is a unit speed length-minimizing path from $p$ to a closest point $s(p)\in S$, we must have $d_S(\alpha(t))=d_S(p)-t$. Differentiating at $t=0$, we get $d(d_S)_p(\dot \alpha(0))=-1$, so $d(d_S)_p \neq 0$.
Edit:
I think that the answer is positive in general. Let $p \in M\setminus{S}$. As observed above, it suffices to prove that there always exist a unit speed path $\alpha(t)$, satisfying $d_S(\alpha(t)) = d_S(p)-t$ for sufficiently small $t$. 

I am quite sure that such a path must always exist; however, the  proof I found is a bit cumbersome. I would be happy to see a cleaner proof, or a different approach to showing $d(d_S)_p \neq 0$.

 A: I prove that there always exist a unit speed path $\alpha(t)$, satisfying $d_S(\alpha(t)) = d_S(p)-t$ for sufficiently small $t$. 
First, note that for every unit speed path $\alpha(t)$ starting from $p$, we have $$d_S(\alpha(t)) \ge d_S(p)-t. \tag{1}$$ Indeed, $d_S$ is $1$-Lipschitz, hence $ d_S(p)-d_S(\alpha(t))  \le d(p,\alpha(t)) \le L(\alpha|_{[0,t]})=t$. 
Now, let $B_{\delta}(p)$ be a normal ball around $p$, such that $d_S(p)>\delta$, and let $S_{\delta}=\partial B_{\delta}(p)$. Let $x_0 \in S_{\delta}$ be a point where $d_S(\cdot)$ obtains a minimal value on $S_{\delta}$. Let $\alpha(t)$ be the (unique) unit speed geodesic from $p$ to $x_0$ which lies inside $B_{\delta}(p)$. 
We shall prove two things:


*

*$\alpha(t)$ minimizes the distance from $S$ inside the sphere $S_t$ for every $t<\delta$, i.e. $d_S(\cdot)$  obtains a minimal value on $S_t$ at $\alpha(t)$. 

*Using $(1)$, we deduce that $d_S(\alpha(t)) = d_S(p)-t$ for sufficiently small $t$.
Proof of 1.:
Assume by contradiction that there exists some $t< \delta$, and $x_0 \in S_t$ such that $d_S(x_0)< d_S(\alpha(t))$. Let $\beta$ be a path from $x_0$ to a point $\tilde s \in S$ such that $L(\beta) < d_S(\alpha(t))$. Since we assumed $d_S(p) > \delta$, $\beta$ must intersect $S_{\delta}$ at some point $y_0$.  Now, we have
$$ L(\beta:x_0 \to y_0)+L(\beta:y_0 \to \tilde s)=L(\beta:x_0 \to \tilde s)=L(\beta)< d_S(\alpha(t)), \tag{2}$$
and
$$  \delta-t+d_S(\alpha(\delta))\le\delta-t+d_S(y_0) \le d(x_0,y_0)+d(y_0,\tilde s) \le L(\beta:x_0 \to y_0)+L(\beta:y_0 \to \tilde s). \tag{3}$$
Combining $(2)$ and $(3)$, we deduce
$$ \delta-t+d_S(\alpha(\delta)) < d_S(\alpha(t)) \Rightarrow \delta-t < d_S(\alpha(t))-d_S(\alpha(\delta)),$$ 
which contradicts 
$$ d_S(\alpha(t))-d_S(\alpha(\delta)) \le d(\alpha(t),\alpha(\delta))\le L(\alpha|_{[t,\delta]})=\delta-t.$$
Proof of $2$:
By $(1)$ we know that $\alpha(t)$ minimizes the distance from $S$ inside the sphere $S_t$ for every $t<\delta$, i.e. $d_S(\cdot)$  obtains a minimal value on $S_t$ at $\alpha(t)$. We shall prove that $d_S(\alpha(t)) = d_S(p)-t$. It suffices to prove that $d_S(\alpha(t)) \le d_S(p)-t$. Assume otherwise; then $d_S(\alpha(t)) > d_S(p)-t$, so $d_S(p) <d_S(\alpha(t))+t$. Thus, there is a path $\beta$, from $p$ to some $\tilde s \in S$ such that $L(\beta)< d_S(\alpha(t))+t$. $\beta$ must intersect $S_{t}$ at some point $y_0$.
(Here we use $t< \delta<d_S(p)$). Thus,
$$ t+L(\beta:y_0 \to \tilde s)\le  L(\beta:p \to y_0)+L(\beta:y_0 \to \tilde s)=L(\beta)< d_S(\alpha(t))+t.$$ So, we got
$$ d_S(y_0) \le d(y_0,\tilde s)\le L(\beta:y_0 \to \tilde s) < d_S(\alpha(t)),$$ and $y_0,\alpha(t) $ both are in $S_t(p)$ contradicting the fact that $\alpha(t)$ was a distance minimizer w.r.t $S$ in this sphere.
