It is generally NOT okay to have a 20A circuit breaker on a circuit that has any 14 gauge wire -- and most homeowners won't run into the exceptions
If there's any #14 wire anywhere downstream, you must use a 15A breaker to protect that wire. It's about fire prevention. #14 wire is rated for 15A. Sure, it will carry more, but the N.E.C. ampacity ratings take into account the resistance of the wire insulation to heat and other factors. Bottom line, #14 wire equals 15A breaker.
It's fine (or even required) to oversize the conductors, but not to oversize the breaker (except under rare circumstances that you'll never need to know about unless you become a licensed electrician or wind up doing funny things with motors that invoke Article 430). #12 wire on a 15A breaker is fine. The wire is protected. For longer runs, for example using #12 wire on a 15A breaker or #10 wire on a 20A breaker will reduce voltage drop. There are calculations for wire size related to voltage drop over distance that tell you when you need bigger conductors.
Why was this done?
Hazarding a guess, the person who did it might have had some #14 Romex lying around the garage. Maybe they didn't want to run out and buy some #12, or felt they couldn't afford it. Maybe they bought #14 on purpose just because it was cheaper and they didn't understand the requirements. Or maybe they reasoned that it was okay since the only load on those #14 wires would be the lights, which would never draw more than about an Amp per fixture. That's true enough, technically speaking, as long as nothing ever goes wrong, but it still illegal (actually illegal, because it violates the N.E.C. rules).
But stuff does go wrong, so you never intentionally create a situation that has the potential to start fires or electrocute people.
A few (far from exhaustive) examples of things that could go wrong include; somebody comes along and replaces one of those fixtures with a bigger fixture, or with one of those fixtures with a receptacle on it, or adds a convenient receptacle elsewhere on the 14 gauge stretch of the same circuit, or both. Or something goes wrong with one of the light fixtures that causes it to steadily draw more current than it was meant to, and all of a sudden you have a circuit breaker that will happily feed 20A onto #14 wire for long periods of time.
That will work. Code depends on where you live, but I can't see anything wrong with making the junction away from the switch.
You might have issues doing all this in the fan box. It might be cleaner to put a small box in the ceiling and do your connections, then have a small run down to the fan.
And be smart with placement of recessed lighting above a fan. You can get a strobing effect which is annoying (and gives some folks headaches).
Best Answer
You can extend the circuit but it is bad practice to put #14 awg wire on a circuit that originates with #12 awg wire. For example; the reason is because someone tosses a mini fridge on the circuit and now the breaker trips, going back to the panel you many years later or the next owner sees #12 wire and installs a 20 amp breaker not knowing or remembering there was 14 in the run. This can result in a fire especially with back stabs in use and the smaller wire size. I have actually found this exact change of events on several occasions over the years. 12 awg is not that much more than 14 awg so it is best to continue with 12 awg , if you go cheap make sure to label the wiring in the service panel as connected to #14 , but even that is a bad practice compared to running #12.