This passage kind of reminds me of when a parent sits down with their young child and talks with them about safety and how to handle some basic situations. As a parent I know those talks intentionally come from a place of "They are old enough that we need to talk through this, but young enough that I need to explain this very carefully." I picture an elderly John sitting down to lovingly sort out for these churches what exactly walking in the Light means and what it doesn't mean. I picture myself with our oldest son taking the time to talk through "just because one of your friends does/says/watches/thinks this doesn't make it right. We don't follow them we follow God's word."
These churches were culturally surrounded by people who almost agreed with the teachings of the Bible. The world was shouting half truths, "I believe in God and Jesus...but not because I have to. Sin isn't really a thing." So John sits down to carefully walk them through, yes sin is an issue and here is how sin affects our identity and here is how to handle sin as a believer.
In 1:5, John again starts where we should always start: who is God? Then in verses 6 & 7 we see two different identity scenarios: one who walks in light and one who walks in darkness. I love how John goes to lengths to include "if we say"....aka it doesn't matter what you say, your allegiances are born out of what you walk in, what you practice.
Moving on down this passage, John lays out two different scenarios for handling sin. The easiest way to see this is to make a little sandwhich. We've got verses 8 and 10 as the "if we say we don't sin" bread and verse 9 as the "If we confess our sin" meat. Why does John seem to emphasize what not to do? Just imagine that you overhear a playmate telling your kid that it's ok to steal if they are only stealing small things. As a parent you want to address that junk head on, leaving no confusion or room for error. Because your child's lack of understanding on the wrongness of their friend's advice could result in their danger. This is why John is making sure to clarify with the true believers against what the Gnostic (salvation through knowledge) culture around them is spewing. Walking around and claiming you don't sin doesn't change that fact that 1. you do sin, 2. your sin separates you from God, 3. there is good news and forgiveness for all who have sinned if we repent and turn to the Father.
It's easy to read this as fluffy, extra advice that I'm kind of passed at this point in my walk. But the truth is, sometimes the condition of my heart is to bow up as if I don't have a sin issue. Sometimes I forget that walking in light means walking in transparency about my sin both with the Lord and with other believers. No, I'm not ever walking around saying that I don't sin. But sometimes I live that way.
Sometimes I act as if I'm beyond sin.
Sometimes I need someone to hold my hand and say "In this family, we don't act like that."