In your command, the I/O redirection > is handled by the current shell. The command is seen by the interpreter as 3 parts:
sudo echo 0
>
/proc/sys/kernel/randomize_va_space
The echo is executed using the superuser privilege while the current shell (with normal user privilege) tries to write to /proc/sys/kernel/randomize_va_space, and thus triggers a Permission denied error.
There are several ways to overcome this. The first way is to run a shell with superuser privilege and pass the command to the shell using the -c switch:
sudo sh -c "echo 0 > /proc/sys/kernel/randomize_va_space"
(You may use sh for POSIX shell and bash for Bash)
Another way is to use the tee command. The tee command copies the contents from standard input to the standard output (usually means the "screen") as well as the listed files. Therefore, the following command prints the character A to the standard output as well as the files output1.txt and output2.txt.
echo A | tee output1.txt output2.txt
In your problem, writing to /proc/sys/kernel/randomize_va_space needs the superuser privilege while echo-ing 0 does not. So, the solution is:
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space >/dev/null
The final redirection to /dev/null prevents the 0 from printing to the screen.