I was looking at the Prelude VII by Bach and noticed that on the measure 23 Bach ended that phrase with a A♭ maj9 chord. I was wondering how often do extended chords show up in Bach's work. When listening the chord sounded kinda of jazzy. Also I have heard of rules being in place during the Baroque area about dissonant chords so how did this one slip through?
It doesn't end the phrase. The G in the soprano and the Bb in the tenor are suspensions, which resolve downward by step on the next beat. The end of the phrase comes later. The rules you mention about dissonances allow just about anything so long as the parts resolve in a prescribed way.
As for how often rich harmonies like this occur in Bach: they're extremely commonplace. They occur because he was composing from the horizontal perspective (thinking of voice leading, the motion of individual voices) as much as the vertical (thinking of harmonies).
Sometimes he comes up with harmonies that would not be heard again for another couple of centuries, like this extreme example from the end of the chorale prelude Kyrie, Gott heiliger Geist BWV 671:
Analysing this passage purely from the vertical point of view (naming the harmonies) would be a messy sort of fun, but might not be fully enlightening, because the passage is as much about the descending motion of the individual parts.
You can read claims that J. S. Bach thought horizontally, not vertically. That's surely too categorical. His mind is unknowable, so it's anyone's guess how much of his thought was on voice leading, and how much the resulting harmonies. It would surely have varied depending on the style and texture he was writing, too. What's beyond doubt is that he gives us plenty to value in both ways.
It's actually a suspension, which is to say that the actual chord is F Minor (F, A-flat, C, in first inversion) but the G and B-flat are held over from the previous chord before moving to F and A-flat. Dissonant suspensions resolving to consonant chords are very common in Baroque music. In jazz, 9th chords are treated as normal chords, so a G#maj9 might follow a D#maj9 and then be followed by a C#maj9 without suspensions.
I knew someone who didn't like modern music because "the dissonances never resolve." That's a fair criticism, I suppose. Bach can have some absolutely crazy sequences of chords, as in the Grave section of the Toccata, Adagio and Fugue in C major for organ (BWV 564), but they eventually resolve to C major. Ives and Stravinsky pound out the dissonances with no resolution. Modern jazz says, "Hey, these so-called dissonant chords are actually very beautiful. Just listen to them. Really listen." Ravel and Poulenc agree.
As the other answer point out you mis-identified the suspension as the end of the phrase, but the resolution is the end of the phrase.
Bach's Prelude #1 from the Well Tempered Clavier, book I is super clear example of extended chords and dissonances. This particular prelude started as an instruction piece for is some Wilhelm so it's original purpose is pedagogical - for teaching - and it's choke full o' chords but relatively easy to play.
It has harmonies that would not be out of place a jazz setting if the rhythm was made to swing. Take a look at this example of
ii7 V7 I...
Am7 D7 G.
Later, at the end, there is a short sequence of consecutive dominant seventh chords...
...mm. 31-33 is
G7 C7 F. That move is very common at the end of classical pieces. It's a brief tonicization of the subdominant. But in this particular passage we get the direct movement from one dominant seventh chord to the next. In the inner voice we have the implied descending chromatic line
B Bb A. That move is common in jazz.
Also the ending displays a pedal bass on the tonic. At m. 34 the full dominant seventh chord is played over the tonic pedal. Of course this is very dissonant. If we consider the pedal
C as the chord root and wrote that chord with a jazz symbol it would be
The is a common harmonic sequence you should be aware of includes seventh chord dissonances on each chord...
...notice that with each chord change the role of the upper voice swap where the chord third is suspended and becomes the next chords seventh and then resolves at the next change to the third and so on as the sequence proceeds.
So, extended chords and dissonances were commonly used, but normally they were carefully treated to resolve.
Some of Bach's "sustained" notes, of which counterpoint practice of the time can tell a different story, may be regarded as deliberately creating a jazzy chord. I can't quite remember, but in uni they showed us an example of very dissonant passage from Bach's work. It's down to to things: harmony can come from polyrhitmic passages as well as homophonic passages, and second, both can be interpreted as having either a counterpunctal or harmonic expression. Given that Bach was composing during a transitional time from counterpunctal way of thinking to a harmonic way of thinking, due to technical innovations in tunings, it's safe to say Bach may have deliberately created jazzy harmonies.