Can a 'bad' SOP keep you out of a program? Can a 'good' SOP help you? Can the SOP only hurt you?
All of the above. Of course the Statement of Purpose is important, or the university would not ask you to write one. It costs time for an evaluation committee to read through every application, and if there were a better way to judge the quality of a candidate, we would use it.
So yes, a bad SOP can totally sink an application. A good SOP can definitely help; it can also explain other issues that a reader might find in your application, such as poor grades or gap years.
[I have been on the faculty committee for Mathematics Graduate Admissions at the University of Georgia for seven admissions cycles, three times as the head of the committee.]
I view the statement of purpose as one of the least important parts of the application. It is certainly a part that has very little correlation with acceptance. In other words, if we look only at, say, the GRE scores or GPA of an application and see that they are extremely high (respectively, extremely low), we can significantly raise (respectively, significantly lower) the chance that that application will be accepted compared to the mean acceptance rate, but a really excellent or really awful personal statement does not change the probability appreciably unless further conditions are met.
Why is this? The main reason is that, for a PhD student of (most likely theoretical, in our department) mathematics, good or bad statements of purpose correlate too weakly with the qualities for which we are trying to select. Good writing skills are important, but because a "statement of purpose" is a genre with which most applicants are completely unfamiliar, how they write in this genre doesn't tell us that much about their general writing skills. (Imagine that we asked them to contribute a haiku or sonnet instead. That sounds ridiculous...but actually does give some idea of the situation.)
The majority of statements of purpose we get mostly try to convey the student's ardor for mathematics, beginning with an anecdote about how it was kindled at an early age. They go on to say something about what kind of mathematics they want to study...and in most cases they will show that they don't really know. As far as our reactions to this: (1) well, we want students who love mathematics, but that is shown better through anything other than how eloquently they write an essay about this love and (2) it is actually okay that most students of (again, mostly theoretical) mathematics have quite vague ideas about what they want to study. My thesis for instance was on abelian surfaces with quaternionic multiplication. This is a topic in arithmetic geometry, which is a subfield of number theory. I believe that in my statement of purpose I said I wanted to do number theory. Good guess!
I will come back later and say more about (1) Why most departments require a statement of purpose anyway and (2) What are some situations in which a statement of purpose becomes more important. I wanted to leave an answer before the question got closed. (It is a good question.)
Added: As Mark Meckes points out in the comments, I have already answered a similar question on this site.