Not something I've really considered...I've witnessed it many times, though.
KT67 wrote:
If someone doesn't know something, they should shut up.
In the hope that thoughts\observations on this subject are permitted, even if they don't constitute "knowledge"...
The suggested "Dunning-Krueger" effect would certainly explain a number of instances I have witnessed, but others seem like the person is simply wishing to be the centre of attention, and lacks the capacity to "retreat" once crossing the limit of their knowledge on a topic (or even to realise they have hit that point), instead pushing on in the hope that no-one challenges them.
Another alternative could be that they have participated in\witnessed discussions around similar topics in the past which resonated with them and are simply repeating what they recall of the "dominant" speaker in the belief that what they heard was true, potentially as they hadn't been exposed to any other information source of the subject previously and so had nothing to measure this new information against.
It also seems much more common (from experience) in an off-line situation (although not restricted to this) due to the difficulty in others supplying information counter to theirs in order to disprove them, so the most "charasmatic"\"confident" person is usually the one whose "input" is retained\"believed" by participants in a conversation, rather than the most knowledgable on the topic.