This, I think, is a mix of understanding the dynamics of the current group, topic, context, and confidence (which can vary depending on the previous aspects). I’m by no means great at this, but I will definitely respond very differently depending on those things.
For instance, if we’re in a casual setting with mostly friends and family on a topic I’m passionate about, I’ll have no problem interjecting. If they’re talking about something I don’t know much about or don’t care much about, I’ll probably just listen unless directly prodded. If we’re in a meeting at work, I’ll very seldom interject because the group dynamics are such that I need to defer to the people running the meeting, but there are times when I know I’m the most knowledgeable on the topic and I need to say something.
Really, though, the only way to get good at it is to practice. I enjoy people watching, and at social settings, I’ll usually just sit back and watch until I see a group talking about something I want to take part in. By that time, I have a feel for the mood and dynamics of the conversation. The other thing to keep in mind is that it’s generally not going to be the sort of thing where you’ll have something particularly deep to say. That works in a one-on-one situation or even one-to-many, where people will wait for your thoughts, but in a many-to-many conversation, the silence will get filled, and the experiences shared will tend to need to stay roughly with what everyone involved has in common, which will tend to mean a bit more superficial. As such, if you’re looking for something deep to say, you’re often going to be stuck not getting to say anything.
For example, if I’m in a social setting and people start talking music, I’ll often participate, even if I’m mostly listening. I’m into pretty obscure music, so where I might ramble on about some awesome album I bought recently in a one-on-one situation, I’ll tend to stick to much more accessible aspects about my passion in music and read how people respond. Like, if they don’t seem so interested, I might try to focus more on stuff they are familiar with, but if they do, I’ll very well pick it up and run with it. Obviously, if I’m with a group of people I’m closer to, we’ll probably be more likely to talk about deeper stuff, but then I don’t so much have to worry about having my turn to speak because they’ll want to hear what I have to say and vice versa.