After Jesus becomes harsh and gets the scribes' and Pharisees' attention,
Matthew 12:34 (NASB)
“You brood of vipers, how can you, being evil, speak what is good? For the mouth speaks out of that which fills the heart.”
two verses later he reminds and warns them of judgment day.
Matthew 12:36-37 (NASB)
“But I tell you that every careless word that people speak, they shall give an accounting for it in the day of judgment. 37 For by your words you will be justified, and by your words you will be condemned.”
The scribes and Pharisees might think Jesus is insulting them, but he’s actually giving them a metaphor, specifically the viper, to almost scare them. He’s warning them. He’s very upset, yet this is the first of two times in Matthew he warns them of what they’ll face later, their day of judgment.
Jesus uses harsh words to describe how wicked the scribes and Pharisees are. While he’s calling them snakes, he's specifically using vipers as the best metaphor everyone listening will understand. Everyone knows the viper is the most dangerous and worst in terms of looks, with double-forked tongues and venomous fangs, but also in what they do. When they aggressively attack and bite to give venom, they don’t let go. Their poisonous bites often lead to painful deaths. Furthermore, they multiply quickly.
While Jesus mentioned the viper to help discipline and warn the scribes and Pharisees, he had already mentioned the scribes and Pharisees to help teach and warn his crowds. He told them to do just the opposite of the "religious leaders".
“For I say to you that unless your righteousness surpasses that of the scribes and Pharisees, you will not enter the kingdom of heaven.” (Matthew 5:20)
“So when you give to the poor, do not sound a trumpet before you, as the hypocrites do in the synagogues and in the streets, so that they may be honored by men.” (Matthew 6:2)
John the Baptist also knew how wicked the “religious leaders” were. In some of his first words in Matthew, John called them vipers, but that was to get their attention and warn them of Jesus.
Matthew 3:7 (NASB)
But when he saw many of the Pharisees and Sadducees coming for baptism, he said to them, “You brood of vipers, who warned you to flee from the wrath to come?"
Four verses later John warned them, but of Jesus (vs. judgment day).
Matthew 3:11 (NASB)
“As for me, I baptize you with water for repentance, but He who is coming after me is mightier than I, and I am not fit to remove His sandals; He will baptize you with the Holy Spirit and fire.
Later in Matthew after the crowds hear Jesus say “Woe to you, scribes and Pharisees” (or “blind” ones guides, fools) seven times, he again calls them vipers and immediately mentions their final sentencing.
Matthew 23:33 (NASB)
”You serpents, you brood of vipers, how will you escape the sentence of hell?
In summary, John the Baptist called the scribes and Pharisees a "brood of vipers" as he warned them of Jesus. What Jesus meant to do when he called the scribes and Pharisees a “brood of vipers” was get their attention and warn about judgment day. At the same time he was using that metaphor to tell his people how dangerous and evil the scribes and Pharisees were (i.e. like vipers); he was warning them also. They'd better not act like either one of them.