My original intuition was that the answer is "no", $g$ is not necessarily measurable, but I have been playing around and I am unable to construct a particular counter-example.
My only idea as to why the answer would be "yes" is by somehow invoking the fact that the product of two measurable functions is measurable.
Any hints would be appreciated!
Choose a non-measurable subset $S$ of $R$ which exists due to axiom of choice , now define $g:R\rightarrow R$ such that $g(S)=\{1\} , g(R-S)=\{-1\}$ ,then $f=g^2$ is constant function so measurable but $g $ is not measurable ,since $g^{-1}(1)=S$ is non- measurable, though $\{1\}$ being a closed subset of $R$ is measurable.