This is one of the things you have to learn in school. I’ve seen many teachers who, when faced with a students’ hand up will first ask them, “Is this something about what we’re talking about? Is it on topic? Is what you’re about to say appropriate?”
And it is remarkable to see hands come down, to see them solving the problem of when and what to speak about in school. It seems as if it should be perfectly natural to understand how to stay on topic but it must be taught. And I know a lot of adults who didn’t learn it.