This is actually Problem $ 17 $ from Chapter $ 10 $ of the Fourth Edition of Michael Spivak’s Calculus. The statement is quite simple, but I have not had any success in finding an example. Here is the statement:
Problem. Give an example of functions $ f: \Bbb{R} \to \Bbb{R} $ and $ g: \Bbb{R} \to \Bbb{R} $ such that $ g $ takes on all values (i.e., is surjective), and $ f \circ g $ and $ g $ are differentiable, but $ f $ is not differentiable.
Note: I want to assume that $ f $ is nowhere differentiable, otherwise the problem is quite easy.
Note that this is in the second chapter of limits, which means that simple examples are expected. No functions defined in terms of integrals or power series should be necessary!
The following proposition provides only a partial response to the latest edit.
Proof
As $ g $ is, by assumption, surjective and differentiable everywhere, there exists an $ a \in \Bbb{R} $ such that $ g'(a) \neq 0 $. Then by the further assumption that $ g': \Bbb{R} \to \Bbb{R} $ is continuous, the Inverse Function Theorem says that we can find an open interval $ I $ containing $ a $ satisfying the following:
We can now write $ f|_{g[I]} $ as the composition of two differentiable functions: $$ f|_{g[I]} = (f \circ g) \circ (g|_{I})^{-1}. $$ By the Chain Rule, $ f|_{g[I]} $ is differentiable on $ g[I] $, so we conclude that $ f $ is differentiable on some open interval at least (if $ g' $ is continuous). $ \quad \blacksquare $
Latest Edit
This latest edit, although it does not answer the question in its entirety, shows that $ f $ cannot be badly behaved everywhere.
Proof
As $ g $ is not constant on $ \Bbb{R} $, there exist by Darboux’s Theorem uncountably many $ a \in \Bbb{R} $ such that $ g'(a) \neq 0 $. Fix such an $ a $, and choose a $ \Delta > 0 $ such that $$ \forall h \in [- \Delta,\Delta] \setminus \{ 0 \}: \quad \frac{g(a + h) - g(a)}{h} \neq 0. $$ In particular, $ g(a + h) - g(a) \neq 0 $ for all $ [- \Delta,\Delta] \setminus \{ 0 \} $. As there is no danger of dividing by $ 0 $, we thus obtain \begin{align} \forall h \in [- \Delta,\Delta] \setminus \{ 0 \}: \qquad ~ & \frac{(f \circ g)(a + h) - (f \circ g)(a)}{g(a + h) - g(a)} \cdot \frac{g(a + h) - g(a)}{h} \\ = ~ & \frac{(f \circ g)(a + h) - (f \circ g)(a)}{h}. \end{align} Equivalently, \begin{align} (\spadesuit) \qquad \forall h \in [- \Delta,\Delta] \setminus \{ 0 \}: \qquad ~ & \frac{f(g(a + h)) - f(g(a))}{g(a + h) - g(a)} \\ = ~ & \frac{(f \circ g)(a + h) - (f \circ g)(a)}{h} \cdot \frac{1}{\left[ \frac{g(a + h) - g(a)}{h} \right]}. \end{align}
Define a function $ I: (0,\Delta] \to \mathcal{P}(\Bbb{R}) $ by $$ \forall \delta \in (0,\Delta]: \quad I(\delta) \stackrel{\text{df}}{=} \{ g(a + h) \in \Bbb{R} \mid h \in [- \delta,\delta] \}. $$ The Intermediate Value Theorem tells us that for each $ \delta \in (0,\Delta] $, the continuity of $ g $ guarantees that $ I(\delta) $ is a closed bounded interval, and as $ g(a + h) \neq g(a) $ for any $ h \in [- \delta,\delta] \setminus \{ 0 \} $, we see that $ I(\delta) $ is also non-degenerate, i.e, it contains points other than $ g(a) $. Next, define \begin{align} L & \stackrel{\text{df}}{=} \{ \delta \in (0,\Delta] \mid I(\delta) \cap (- \infty,g(a)) \neq \varnothing \}, \\ R & \stackrel{\text{df}}{=} \{ \delta \in (0,\Delta] \mid I(\delta) \cap (g(a),\infty) \neq \varnothing \}. \end{align} By the foregoing discussion, we have $ L \cup R = (0,\Delta] $. Hence, either
Without any loss of generality, we may assume it is Case (1) that occurs.
Note: The cases are not mutually exclusive, i.e., both could occur.
By our assumption that Case (1) occurs, we have $ I(\Delta) \cap (- \infty,g(a)) \neq \varnothing $. As such, let $ (y_{n})_{n \in \Bbb{N}} $ be any sequence in $ I(\Delta) \cap (- \infty,g(a)) $ that converges to $ g(a) $. We boldly claim that $$ \lim_{n \to \infty} \frac{f(y_{n}) - f(g(a))}{y_{n} - g(a)} = \frac{(f \circ g)'(a)}{g'(a)}, $$ which would imply that the left-derivative of $ f $ at $ g(a) $ exists.
Define a sequence $ (h_{n})_{n \in \Bbb{N}} $ in $ [- \Delta,\Delta] $ by $$ \forall n \in \Bbb{N}: \quad h_{n} \stackrel{\text{df}}{=} \text{A number $ h \in [- \Delta,\Delta] $ closest to $ 0 $ such that $ g(a + h) = y_{n} $}. $$ Such a $ h $ exists because $ {g^{\leftarrow}}[\{ y_{n} \}] \cap [a - \Delta,a + \Delta] $ is a non-empty compact subset of $ \Bbb{R} $. So as to avoid using the Axiom of Choice at this stage, we choose $ h_{n} $ to be positive whenever possible.
We argue that $ \displaystyle \lim_{n \to \infty} h_{n} = 0 $. Assume the contrary. Then we can find an $ \epsilon > 0 $ and a subsequence $ (h_{n_{k}})_{k \in \Bbb{N}} $ of $ (h_{n})_{n \in \Bbb{N}} $ such that $ |h_{n_{k}}| \geq \epsilon $ for all $ k \in \Bbb{N} $. Choose a $ \delta \in (0,\epsilon) \cap L $ (this is where the assumption of Case (1) plays a role). As $ I(\delta) \cap (- \infty,g(a)) = [m,g(a)) $ for some $ m < g(a) $, we are able to find a $ K \in \Bbb{N} $ sufficiently large so that $ y_{n_{K}} \in I(\delta) $. It follows that $ y_{n_{K}} = g(a + h) $ for some $ h \in [- \delta,\delta] \subseteq (- \epsilon,\epsilon) $, which makes $ h $ even closer to $ 0 $ than $ h_{n_{K}} $ is — a contradiction.
Using $ (\spadesuit) $ now, we therefore get \begin{align} \lim_{n \to \infty} \frac{f(y_{n}) - f(g(a))}{y_{n} - g(a)} & = \lim_{n \to \infty} \frac{f(g(a + h_{n})) - f(g(a))}{g(a + h_{n}) - g(a)} \\ & = \lim_{n \to \infty} \frac{(f \circ g)(a + h_{n}) - (f \circ g)(a)}{h_{n}} \cdot \frac{1}{\left[ \frac{g(a + h_{n}) - g(a)}{h_{n}} \right]} \\ & = (f \circ g)'(a) \cdot \frac{1}{g'(a)} \qquad \left( \text{As $ \lim_{n \to \infty} h_{n} = 0 $.} \right) \\ & = \frac{(f \circ g)'(a)}{g'(a)}. \end{align} Therefore, $ f $ has a left-derivative at $ g(a) $. If we were to assume Case (2) instead, it would have a right-derivative at $ g(a) $. In any case, $ f $ has a one-sided derivative at $ g(a) $, and as we have shown in the beginning that there are uncountably many such $ a $, we are done. $ \quad \blacksquare $