It's all to do with evaluation order.
In the first example, the script engine thingie comes across the $null, and its first 'thought' is that this is something to execute. it's second thought is that this something is a null value, and so does nothing. but at the top-most level, there is something there: the plain-text "$null". (Note this is why extra evaluation in scripting normally requires TWO sets of eval brackets)
In the second example, the engine's first thought is that '|' is something to execute. With this logic, '| echo -a test' is the line to execute, which is why you get the server error, because there is no '|' command, with or without the extra text. If there was more text before the pipe character, it would assume THAT to be a command on its first thought.
| is, just lke $null, a second-evaluation device. | and $null are plain text, but when evaluated (if given the chance), they become a newline, and empty space.
I realise this is a very confusing post. But I believe at least some of it makes sense
Note: the idea of 'thought' here is synonymous with that of evaluation. I just like the word better.