This is a homework question and I would appreciate if someone could check my reasoning. This seems too simple to be true.
Proof: Assume there exists $X$ with a non-constant function $f:S^n\rightarrow X$ such that $f\not\simeq c_x$. This implies that $1 = |\pi_0(S^n)|\neq|\pi_0(X)| \implies |\pi_0(X)| \geq 2 \implies X$ is non-contractible.
Your proof does not make sense. What you try to show is that if there exists $f : S^n \to X$ which is not homotopic to a constant function, then $X$ is not contractible. This is trivial: If $X$ is contractible, then all $\phi : Y \to X$ are homotopic to a constant function. In your "proof" you claim that $X$ is not path-connected (i.e. $\pi_0(X)$ has more than one element), but this is wrong. The identity map on $S^n$ is not null-homotopic, but $S^n$ is path-connected for $n > 0$.
The Warsaw circle $W$ is an example of a compact metrizable space which is not contractible, but having all $\pi_i(W) = 0$.
See