Do I need to shut the gas off to my fireplace before I replace the wall switch?
Generally speaking it's not necessary.
Disconnecting the switch is no different than turning the switch off. Both can create tiny sparks and both leave the fireplace without power. Of course, if you turn off the breaker as you should, sparks are less likely.
Either you have an electronic gas valve, in which case it'll remain closed, or you have a pilot flame, in which case it'll continue burning. Both are safe conditions.
This is like "do i need to turn off the engine while pumping gas?".
The answer is always YES. Because you need to prepare precaution.
The leaking gas can be smelled but our nose could be blocked by cold or flu and change the sense of smell, making it hard to smell the leaking gas.
If the gas starts to leaks while you replacing the wall switch you could panic and making the decision while panic is never ended well.
Unless the gas line is far away from your wall switch you don't need to shut off the gas.