No idea what he was thinking, but it's a beautiful passage for sure! The Nocturne has overall a quite mournful and expressive character, and just before this passage is a brief moment in C major, offering some warmth and respite from the sadness. The circled passage has a simple melody with a common chord progression which is often used to escalate the tension, and it effectively ramps up the expression returning to minor keys, creating a mournful buildup to a small climax before the B section which is in major.
Haha that kinda sounded like ChatGPT wrote it, I promise it was me!
In short, I think Chopin wanted to ramp the tension, sadness and expression back up after a brief respite in C major
