I recently did the following exercise:
$X$ is a path-connected space and $\pi_1(X)$ is finite. $h:X\to S^1$ is a continuous map. Prove that $h$ is null-homotopic.
I am wondering about this: what are some interesting examples of $X$? I cannot find any space with non-trivial finite fundamental group. How can I construct one? I want to know some examples of $X$ that are not contractible where this theorem applies.
Here's a general construction:
Claim: $\pi_1(X) \cong G$.
Now to answer your question, just take any finite $G$. For a nice example, work out the construction where $G$ has a single generator, i.e. is cyclic.
(It's worth pointing out that with a little more work you can prove that actually every finitely presented group is the fundamental group of some compact $4$-manifold.)
For examples of $X$ that are not contractible, note that if $\pi_1(X) \neq 0$ then certainly $X$ is not contractible, so my above construction provides examples. Moreover if $\pi_1(X) = 0$ but some higher homotopy group is non-zero then it will still be not contractible. For example if $n>1$ then $\pi_1(S^n) = 0$ so the exercise you did verifies that any continuous map $S^n \to S^1$ is nullhomotopic for $n>1$, or in other words $\pi_n (S^1) = 0$ in this range, but still $\pi_n(S^n) \cong \mathbb{Z}$ so it is not contractible. There are many other examples of spaces where $\pi_1(X) = 0$ but $X$ is not contractible, even spaces where all of the homotopy groups vanish (for example the Warsaw Circle).