Has anyone else's children made really odd statements?
Often.
I start to wonder if it's baked in to BPD-type family systems. The kids are 17 & almost 15 now. SD17 is pretty tight lipped about content, but the
way she communicates says a lot -- what she gets defensive about, who she blames, etc.
SD14, though, doesn't have the enmeshment/hypervigilance that gives her a sense of "Mom wouldn't want me to say XYZ" so she tends to spill a lot that she doesn't realize is actually spilling a lot.
Even the kids' mom (many BPD type traits), I've realized over time, is a huge over-sharer, though I don't think she realizes she is, and it shows up as her explaining how things aren't her fault (translation: it is), or how what she and Stepdad (many NPD type traits) do is amazing, superior, and enlightened (translation: it isn't).
This meant that about a year+ before Mom knew (or allowed herself to see), based on stuff she said and the kids said, I suspected that there was something funny relationally between Stepdad and a female family friend. Fast forward about a year and a half, and SD17 is breaking down emotionally because of what she terms "adult relational chaos" at Mom's house -- though she only said that much after spending half the conversation blaming DH for "overreacting about her grades". She had to make it fair, apparently

Around the same time, SD14 and I were working on crafts and she was telling me about watching some of the Muppet Show in a class at school. It was some episode about Kermit and Miss Piggy, and she said something like "you can't just tell someone you love them and then go be with someone else" (ostensibly about the muppets).
Anyway, looks like Stepdad is in some kind of romantic relationship with this female family friend now, though apparently he and Mom are still married. Guess it's "enlightened".
With either kid, I can't push super hard, because SD17 gets defensive still, and SD14 shuts down. But, with SD17, what I did was say "Whatever is going on, I see things, and I hear things, and I wasn't born yesterday. Whatever it is, if you want to tell me, I won't be shocked or surprised, and I probably already guessed what it was. It's also OK if you don't want to tell me, but the most important thing for me and Dad is that there is someone neutral you CAN talk to. So, if you want help setting up counseling, let us know, and we will do it for you."
With SD14, my approach is to have minimal reactivity to anything she says (that can trigger her feeling shamed and shutting down) and to try to draw parallels to friend dynamics -- was this or that toxic, what do you think she wanted when she did that, what would you do if you were in that position, etc. So, at least she is thinking about the structure of the situation, even if it is too fraught for her to think about the specifics. DH also watches a show with her that has a lot of conversation points for relationships.
...
So -- you did well to just respond to your son with the question "Why did you say that?" I kind of suspect he did hear it from somewhere, but whether that's from a friend at school, a TV show, your W, family member conversations, etc, is hard to say. I think that part of his brain is online enough to put together "Hmmm, this and that situation are alike", but he isn't mature enough to have the nuanced conversation of "well Dad, my friend told me that his mom got angry a lot and then got a boyfriend, and Mommy gets angry, so that's why I said that, I thought it was similar", and he may sense some shame around it, which sends him to the "I don't know why I said it" outlet.
One positive thing you can do in these situations is to give yourself a few seconds to compose yourself by doing just what you did, replying with a question:
"Oh really?" (note, tone makes a HUGE difference here, so use a tone that is warm and not dismissive)
"Yeah? Are you concerned about that?"
"Oh, were people talking about that?"
and then, once he replies, and you've got your feet a bit more under you...
always turn the focus back to how he feels.
"How were you feeling when your brain thought that, buddy?"
"Are you having any feelings about that?"
A lot of what you say will depend on his answer, and he's only 5, so it doesn't have to be hugely complicated. But these "weird comments" that the kids make are a huge opportunity in BPD family dynamics for you to model calmness, non-reactivity,
focus on the kids' feelings, validation, non-shaming, and support.
It's a big deal that he felt safe enough to make that kind of comment with you. You can really keep the doors open by staying warm, focused on his feelings, non-shaming, present, and validating to him. You can reinforce that by telling him: "I'm glad you felt like you could share your brain thoughts with me!" or "I'll always do my best to listen to you, whenever you want."
Keep the focus on his feelings (vs "mining for information"), and he'll open up. I think kids sometimes want to get this kind of stuff out in the open. Or, even if they think they don't want to, it comes out, and then it's our job as adults to not send the focus to the BPD/NPD adult ("I can't believe your stepdad is doing that kind of stuff", "Why doesn't your mom actually pay attention to you"), but back on the kid where it belongs.
Hope that's a helpful direction, and you're definitely not alone;
kells76