For a Von Neumann architecture (the most common today), programs and data are stored in the same memory. So, there has to be a distionction of what is a program and what is data. Moreover, without a control of what is executed, many programs can do malicious jobs. One way to prevent malicious programs from doing bad things is, at the execution of the program, to load the code in a read only, executable memory region and to use as a stack a writable memory region that cannot be executed.
There is a thing called program counter that points to the current instruction being executed. A program may change its value to point to the stack and execute malitious instructions from there, that can be recieved over the network, for example, givin access to an unauthorized person to your machine.
Also, in the linux operating system, there is a permission system that allows you to specify whether a file can be executed or not and by which persons.
This thread: Linux process memory scheme has a pretty explicit image of how the memory of a process is organised. Only the text section, that contains code, is executabile (this means that the program counter can point to a memory cell only in that region).