I'd like to know an explicit example of a compact, connected manifold $M$ and a smooth function $f\colon M \to \mathbb{R}$ which satisfy the following properties:
- We denote by $m$ the minimal value of $f$. Then there is an unique point $p$ on $M$ such that $f(p)=m$.
- By (i), $p$ is a critical point of $f$. I assume that $p$ is an isolated critical point. But I also assume that $p$ is a ``degenerate" critical point.
- Let $c$ be a real number which is slightly bigger than $m$. Then the level set $f^{-1}(c)$ is not homeomorphic to a sphere.
Note: if $p$ is a non-degenerate critical point, then Morse lemma shows that $f^{-1}(c)$ is a sphere.
In my answer I will give some examples, by slackening condition 2 to the assumption that $p$ is a degenerate critical point (so I do not require that it is an isolated critical point).
Let us first construct a 1-dimensional example. Consider the even function $g:\mathbb{R} \rightarrow \mathbb{R}$ defined by \begin{equation} g(x)= \begin{cases} x^2 + e^{-\frac{1}{x^2}} \sin^2\frac{1}{x^2} & \text{if $x \in \mathbb{R} \backslash \{0\}$,} \\ 0 & \text{if $x=0$.} \end{cases} \end{equation}
This is a smooth function which attains its minimum only at $x=0$. Anyway, since the function oscillates around zero, for any local maximum $x_n$ of $g$ if you choose values of $c$ slightly smaller than $g(x_n)$, the level set $g^{-1}(c)$ contains at least four points, so it is not a 0-dimensional sphere. Now, to build an example on a compact, connected manifold $M$, let $\phi: \mathbb{R} \rightarrow \mathbb{R}$ be a smooth function such that $0 \leq \phi(x) \leq 1$ for all $x \in \mathbb{R}$, $\phi(x)=1$ for $x \in [-1,1]$ and $\phi(x)=0$ for all $x$ such that $|x| > 2$ (for the existence of such a function see e.g. Rudin, Functional Analysis, $\S 1.46$), and set \begin{equation} f(x)= g(x)\phi(x)+1-\phi(x) \quad (-\pi \leq x \leq \pi), \end{equation} (note that for each $x \in [-\pi,\pi]$, $f(x)$ is a convex combination of $g(x)$ and $1$). By extending $f$ on all of $\mathbb{R}$ by setting $f(x)=f(x+2\pi)$ for all $x$, we get a smooth periodic function of period $2\pi$, that is a smooth function on the circle $M=S^1$, which satisfies all the required properties.
We can easily use the previous example to construct a 2-dimensional example. Define \begin{equation} G(x,y)= \begin{cases} x^2+y^2+e^{-\frac{1}{x^2+y^2}} \sin^2 \left( \frac{1}{x^2+y^2} \right) & \text{if $(x,y) \in \mathbb{R}^2 \backslash \{(0,0)\}$,} \\ 0 & \text{if $(x,y)=(0,0)$.} \end{cases} \end{equation} where for every $r > 0$, we set $B(r)=\{(x,y)\in \mathbb{R}^2 : \sqrt{x^2+y^2} \leq r \}$. Now again, by the already quoted result in Rudin, Functional Analysis, $\S$ 1.46, there exists a smooth function $\Phi:\mathbb{R}^2 \rightarrow \mathbb{R}$ such that $0 \leq \Phi(x,y) \leq 1$ for all $(x,y) \in \mathbb{R}^2$, $\Phi(x,y)=1$ for $(x,y) \in B(1)$ and $\Phi(x,y)=0$ for all $(x,y) \notin B(2)$. Define for each $(x,y) \in \mathbb{R}^2$: \begin{equation} F(x,y)= G(x,y)\Phi(x,y)+1-\Phi(x,y) . \end{equation}
Take $M=S^2$, and consider the stereographic projection $p:S^2 \backslash \{(0,0,1)\} \rightarrow \mathbb{R}^2$:
\begin{equation} p(x_1,x_2,x_3)=\left( \frac{x_1}{1-x_3}, \frac{x_2}{1-x_3} \right). \end{equation}
Then by setting $f=F \circ p^{-1}$, and extending $f$ to all of $S^2$ by putting $f(0,0,1)=1$, we get a smooth function $f:S^2 \rightarrow \mathbb{R}$ satisfying all the required hypotheses. In particular, for every $\epsilon > 0$, there is some $c$, with $0 < c < \epsilon$, such that $f^{-1}(c)$ has at least two connected components, each one homeomorphic to $S^1$.
NOTE. The author of the post has published some years ago a paper bearing the title On the Level Set of a Function with Degenerate Minimum Point in which he proves a complete answer to his question. In particular, he shows that under the hypotheses that $p$ is an isolated critical point, we can find a neighborhood $U$ of $p$ in $M$ such that for each $c > m$, the c-level set of $f_{| U}$ is a homeomorphic to a sphere.