Here is a complete answer. We show $f$ is $C^2$, and then the full result will follow from user479223’s derivation. The following idea follows the suggestion of John Dawkins on the MSE post, and was also independently suggested to me in private communication by user479223.
Let $K$ be a second anti derivative of $h$, i.e. $K’’ = h$. By Itô’s lemma applied to $K$, and the formula in the problem statement applied to $f$, we have that $f(B_t) - K(B_t)$ is a continuous local martingale.
Since if a continuous function of a Markov martingale is a martingale, the function has to be affine linear, we then have that $f - K$ is a affine linear function, that is, of the form $ax + b$, from which it follows that $f$ is $C^2$, and $f’’ = K’’ = h$ as desired.
An alternate derivation:
What follows is not strictly necessary, however as the ideas may be relevant for the multidimensional case or in the less smooth case, I chose to write it up. In the following we show “by hand” that $f$ is $C^1$ with $f’ = g$. This may allow us to deduce a converse of Itô’s lemma for less smooth functions.
We show that $f$ is right differentiable, the left differentiability follows the exact same proof by symmetry.
Note that since almost surely, the equality in the problem statement holds for all $t$, we have also
$$f(B_\tau)=f(B_0)+\int_0^\tau g(B_s) \, dB_s +\frac{1}{2}\int_0^\tau h(B_s) \, ds$$
for all stopping times $\tau$.
Now fix arbitrary $x$, and let $\psi = \inf \ \{ t \in \mathbb R \, \vert \, B_t = x\}$. Then $W_t := B_{\psi + t} - B_{\psi}$ is a standard Brownian motion independent of $\mathcal F_\tau$, and we have,
$$f(W_\tau)=f(W_0)+\int_0^\tau g(W_s) \, dW_s +\frac{1}{2}\int_0^\tau h(W_s) \, ds.$$
almost surely for all stopping times $\tau$.
Now for all $h > 0$, set $\tau_h := \inf \, \{t \in \mathbb R \, \vert \, W_t = h \}.$
We then have that
\begin{multline*}
\frac{f(x + h) - f(x)}{h} \\
= \frac{f(W_{\tau_h} + x) - f(x)}{h} \\
= \frac{\int_0^{\tau_h} g(W_s + x)\,dW_s}{h} +\frac{1}{2h}\int_0^{\tau_h}h(W_s + x) \, ds.
\end{multline*}
For the first term, we have
\begin{multline*}
\frac{\int_0^{\tau_h} g(W_s + x)\,dW_s}{h} \\
= \frac{\int_0^{\tau_h} g(x) \,dW_s}{h} + o(1) \\
= \frac{g(x)W_{\tau_h}}{h} + o(1) \\
= \frac{g(x) h}{h} + o(1) \\
= g(x) + o(1)
\to g(x).
\end{multline*}
as $h \to 0^+$, where the $o(1)$ notation denotes a term that goes to $0$ in probability as $h \to 0$.
While for the second term, we compute
\begin{multline*}
\frac{1}{2h}\int_0^{\tau_h}h(W_s + x) \, ds \\
= \frac{1}{2h} \int_0^{\tau_h} h(x) \, ds + o(1) \\
= \frac{h(x)}{2} \cdot \frac{\tau_h}{h} + o(1)
\to 0
\end{multline*}
in probability as $h \to 0^+$, where the limit in probability of $\frac{\tau_h}{h}$ can be computed directly to be $0$ from the explicit density of $\tau_h$.
We conclude
$$\lim_{h \to 0+} \frac{f(x + h) - f(x)}{h} = g(x)$$
and since $x$ was arbitrary, $f' = g$ as desired, and $f$ is $C^1$.