I have 14 gauge wire on a 15 amp breaker. I want to add a ceiling fan, so from the switch that’s fed by 14 gauge wire. Should I continue to feed the fan with 14 gauge wire or would it be OK to feed the fan from the switch with 12 gauge wire?
You can always up size wire from the minimum required by code, therefore yes, you can do your new wiring extension with #12 on a 15A breaker. Note that when you start getting into big wires, you run into issues with connectors, but at #12 & #14 size, standard wire nuts, Wagos, etc. will all work just fine.
There is a cost associated with going with bigger wire, so unless you’ve got some #12 sitting around, burning a hole in your pocket, #14 would be less expensive.
There are recommendations to add a label to the panel if you have a 15A breaker with #12 wire going to it and #14 wire elsewhere in the circuit, but in your case, with just one run of #12 between switch & fan, there shouldn’t be any need to worry about that. Nobody will be confused when they open the panel and see #14 going into the 15A breaker.
If your fan also has a light and they can be run from a pair of switches (as opposed to either the lights or fan being controlled by a remote) and only has one neutral at the ceiling, you’ll want to run a /3 cable (black, red, white, ground) so that you’re not paralleling your neutral with two separate runs of /2 cable.