This kind of thing is caused by an extreme version of Alienation Syndrome combined with feelings of utter lack of control over their own life. The person feels that literally the only way they have of getting any attention from a society that doesn't even reject them but rather seems completely oblivious and impersonal to them is to MAKE society notice them. Usually this means forcing those they feel were most oblivious to take notice - a sort of 'PAY ATTENTION!' written in blood. In this way, they are empowering themselves and forcing society to acknowledge their existence - two things they feel they have never had. For most if not all, it is intended to be a final act. The perception of their own lives as being utterly pointless, empty and thus of no value is the final part of the equation.
The reason why so many speak of their plans beforehand is simply that they hope someone - anyone - will take them seriously enough to pay attention to them and treat them as if they matter.