You will get differing answers about this, but it's my belief that the author, S.E. Hinton, wanted to point out the fleeting nature of life...that it CAN and DOES end early, sometimes when we least expect it and when we least need or want it to. Yes, it is very unfortunate and sad that Johnny and Dally had to die in the book; however, that is real life. I believe Hinton purposely chose to portray her characters realistically and without the "fairy tale ending" because she wanted her readers to see that life, even in books, is full of ups and downs (sometimes very LOW "downs").
I do not think any reader would want Johnny or Dally to die, but that was their deaths taught other characters valuable lessons about life and about their priorities and their feuds with others.