You don't actually need the continuity of $f$ for that, it suffices that $f$ increases monotonically.
If $x_1 \leq x_2 \leq x_3$ and $x_1,x_3 \in S$, then by the monotonicity of $f$, $f(x_1) \leq f(x_2) \leq f(x_3)$. Together with the definition of $S$, this yields $$
c \leq f(x_1) \leq f(x_2) \leq f(x_3) \leq d
$$
which means $x_2 \in S$. Thus whenever $S$ contains two points $x_1,x_3$, it also contains all points $x_2$ between $x_1$ and $x_3$, meaning $S$ is an interval.
If, instead of $S$, you look at the image of $S$, i.e. at $f(S)$, then you need the continuity of $f$ to show that $S$ is an interval. The argument is similar to the one above, except that you additionally need to invoke the intermediate value theorem.