Chopin was of course very good at harmony, and one of his specialties were chromatic progressions. The particular bars you picked are quite complicated, so I will explain a few different concepts first, before explaining the progression in question.
(Very) broadly speaking, there are two ways to connect chords in a progression: through functional harmony and through counterpoint (voice leading). These two often overlap, since a functionally logical progression typically has very straightforward voice leading.
The two bars you are referring to are not connected through functional harmony, but through voice leading, using some chromatic alterations (these are what makes the progression difficult to fit in a functional progression).
First, let's just consider a B major-minor seventh chord (or B7, for jazz readers). A common chromatic alteration would be to sharpen the root while leaving the rest of the chord as is, creating a B# diminished seventh chord. Of course you can explain this in a functional context (with the diminished chord being a secondary dominant, probably preparing a deceptive cadence) but this is highly dependent on the context (mainly the resolution of the diminished chord). Much simpler is the contrapuntal explanation: a chromatic alteration (raising) of the root note.
A different voice leading trick is voice exchange: two voices exchanging their notes. So let's consider our B major minor chord again, in root position, narrow voicing. This means the bass has the root (B), and the soprano has the seventh (A). The rules of voice leading allow us to change the chord to a third inversion by having the bass descend stepwise to the seventh of the chord (B -> A) and the soprano ascend stepwise to the root of the chord (A -> B). Normally sevenths have to resolve downwards (in strict voice leading) while here the A goes up, but this is fine since we are not resolving it, but merely moving it to a different voice (where it will hopefully resolve properly later). Note that voice exchange doesn't require stepwise motion (an exchange that requires jumps is completely fine too – in fact voice exchange is a common trick to rearrange voices) but this seemed the simplest and most applicable example.
A third technique is the use of passing tones. In simplest terms, if a voice is moving up or down a third it doesn't need to jump, but can go through the tone in between as well, without that note being part of the harmony. So suppose we have a B major triad in four voices with both soprano and alto on the fifth and we want the soprano to move to the seventh we could just have it jump (F# -> A), but it would be fine to include the G# as well (or G natural in minor or as moll-dur). The passing tone (G# here) would normally be between beats or on a weak beat. This would not change the harmony at all. An extension of this principle is the chromatic passing tone: when moving by a major second you can move by a minor second twice instead. For example, let's consider a B major chord with the root in both the bass and the soprano. We want to change the triad to a seventh chord by having the soprano descend to the seventh. As in the previous example, we can do it directly (unlike the previous example, here it would be a stepwise move), but we can put the A# in between, having the soprano go B -> A# -> A with the A# again being on a weak beat. When doing this, you typically wouldn't include a B major seventh chord in your harmonic analysis (since the passing note is irrelevant to the harmony) but fairly frequently there are situations where it is unclear and/or subjective whether a note is a passing note or part of the harmony.
Chopin combined these three things in the two bars you mentioned, which I will now construct in two steps from the above concepts.
If, for a moment, we ignore the D# minor chord in second inversion in the second half of bar 21, we see first a B major minor chord in third inversion, then a B diminished seventh chord in root inversion. This is a combination of voice exchange (basically the reverse of what I described in the relevant paragraph) and chromatic alteration: while the B in the soprano is moving to an A, the A in the bass is moving not to a B, but to a B#!
This leaves us with a problem, though, since this means the bass is moving by an augmented second (A -> B#). We consider this bad voice leading. (Why? Because.) Fortunately, Chopin solved this by putting an A# in between (A# -> B# is only a major second so the voice leading problem is avoided). This is the chromatic passing tone we went over earlier, although slightly extended (since here it's a passing tone between to notes that are an augmented second apart). This is still well within the bounds of passing notes in strict voice leading (it is a stepwise motion between two notes that are part of the current harmony). This combined with the voice exchange I described in the previous paragraph gives us the progression you asked about.
A last side-note: in your analysis you label the D# minor chord as such. You might have noticed that in my analysis, this chord doesn't appear, but is merely a by-product of simultaneous passing notes. As I mentioned earlier, quite often it is unclear whether a note should be consider a passing tone or part of the harmony. Here I think the A# is clearly a passing tone for two reasons:
- The D# minor chord would have no clear connection to the rest of the progression (since there are so many As it doesn't even seem to fit in the scale currently used)
- Chords in second inversion are unstable and need to be resolved since they include a fourth on the bass which would need to resolve to a third (in the strictest voice leading). I'm not saying it is impossible for a second inversion chord to appear without proper resolution but it is very unusual while at the same time we have a much more "proper" explanation available. Additionally, Chopin is quite strict when it comes to harmony rules (as opposed to for example Liszt who had no problems writing unresolved second inversion chords and did so frequently).
After all this, you might have figured out bar 23-24 already, but it's a combination of the same techniques: first we have a voice exchange (B -> A and A -> B) with a chromatic passing tone (A#) in between, afterwards a chromatic alteration (B -> B#) combined with the resolution of the seventh (A -> G#). Again this is quite difficult to explain using functional analysis, but it obeys all the rules of counterpoint.
I hope this is clear enough. Since Chopin is so elegantly combining so many tricks at once I imagine this can be very confusing (especially if the above material is new to you).
Bar 21-22 is a progression that is connected through counterpoint, not through functional harmony. First we have a chromatic passing note (A#) while exchanging B and A in bass and soprano, leading to a chromatic alteration (B# instead of B) in the bass. Then bar 23-24 has the same passing note (A#) but the chromatic alteration is delayed by half a bar, where it is combined with the resolution of the seventh on the B chord.