I noticed that when I triple click (with mouse) to select text (or a command) from say a website, and then paste this into my terminal using Ctrl+Alt+v, then the command runs immediately (i.e. it automatically inputs Enter key), but if I select(with mouse) and copy the same command and use Ctrl+Alt+v to paste it into the terminal it does not auto-run the code but it rather just pastes it and awaits input from me before the code will run.
Which mechanism makes this so? Because I would rather first look at the command to be run before running it, but I noticed this will be done for me any time I use triple click to select a word.
Triple-clicking selects the whole line, which includes the line feed at the end1. A line feed character (Unicode U+0A) is what Enter inputs, so the shell interprets this to mean it should execute the command2.
When you click and drag to select the line, you normally don't select the line feed at the end, unless you drag the mouse down to the next line, or unless you select multiple lines (which of course include multiple line feeds between them).
The best workaround I know is to copy-paste the command into a text editor (e.g. Gedit), review it, then copy-paste it into the terminal.
Here are some harmless commands you can try copy-pasting in different ways:
Footnotes
Both of these were selected by dragging, not triple click. The difference is that, in the latter, I dragged to the next line. You can see the newline being represented as an extra space that does not actually exist in the text. With triple click, you'll always see the latter.
You might want to do either of:
switch to a shell like zsh, which does not execute a command on pasting even if it has newlines. This is pasted text, as yet unexecuted: