As others have mentioned, the problem occurs when the pasted text contains newline characters. With that knowledge, your question is more-or-less the same as this one on Server Fault. Different site, so I'll repeat my answer here…
What you want is called 'bracketed paste', a feature that's available in some shells.
Assuming you're using a recent version of the bash shell, you can turn it on for the current session like so:
bind 'set enable-bracketed-paste on'
Now try it out by pasting multiple lines:
echo Hello world
echo Again, I say, hello!
The shell recognises that the text was pasted (not typed), and waits with a prompt for your confirmation. If it all looks safe to proceed, hit the Enter key. If not, hit Control-C to cancel.
If you'd like to enable bracketed paste for every new session, add the command to your .inputrc file:
echo "set enable-bracketed-paste" >> .inputrc
Another option is to switch from bash to zsh, where bracketed paste is enabled by default. To replace your current shell with a zsh shell:
With zsh, pasted text gets highlighted, which is nice. Again, hit Enter to execute the command/s or Control-C to cancel.
If you like zsh, and wish to make it the default shell:
chsh -s /bin/zsh