It is more elegant to regard $S^n$ as a subset of $\mathbb R^n \times \mathbb R$ and to write
$$f(x) = \begin{cases}
\left(\sin(\pi \lVert x\rVert)\dfrac{x}{\lVert x\rVert},\cos(\pi\lVert x\rVert)\right)& x\neq 0\\
(0,1) & x=0.
\end{cases}$$
Now let $(y,t) \in S^n$, i.e. $\lVert y \rVert^2 + t^2 = 1$. This implies
$\lVert y \rVert^2 \le 1$, i.e. $y \in D^n$.
$t^2 \le 1$, i.e. $t \in[-1,1]$ and there exists a unique $s_t \in [0,1]$ such that $\cos (\pi s_t) = t$.
Case 1. $t = 1$. Then $\lVert y \rVert^2 = 0$, i.e. $y = 0$. Thus $f(0) = (0,1) = (y,t)$.
Case 2. $t = -1$. Then $\lVert y \rVert^2 = 0$, i.e. $y = 0$. For any $x \in S^{n-1} \subset D^n$ we have $\lVert x \rVert = 1$ and thus $f(x) = \left(\sin(\pi 1)\dfrac{x}{1},\cos(\pi 1)\right) = (0,-1) = (y,t)$.
Case 3. $-1 < t < 1$. Then $t^2 < 1$ and hence $\lVert y \rVert^2 > 0$, i.e. $y \ne 0$. Let $x = s_t\dfrac{y}{\lVert y \rVert}$. Then $\lVert x \rVert =s_t$. Note that $0 < s_t < 1$ in case 3. We claim that $\sin(\pi \lVert x\rVert)\dfrac{x}{\lVert x\rVert} = y$ which shows that $f(x) = (y,t)$. We have $\sin(\pi \lVert x\rVert)\dfrac{x}{\lVert x\rVert} = \sin(\pi s_t)\dfrac{y}{\lVert y\rVert}$, thus it suffices to show that $\dfrac{\sin(\pi s_t)}{\lVert y\rVert} = 1$. Since $0 < s_t < 1$, we have $\sin(\pi s_t) > 0$, thus it suffices to show $\sin^2(\pi s_t) = \lVert y\rVert^2$. But this is clear since $\lVert y\rVert^2 = 1 - t^2 = 1- \cos^2(\pi s_t) = \sin^2(\pi s_t)$.