I like V. Rossetto's answer (+1), but I think the level of cynicism it contains is more appropriate as an answer for why bad papers are published (to which I would add that there is now a glut of mediocre venues looking for content ... everyone wants to be editor or co-organiser of something; and I would also add that, unfortunately, authoring and peer-review is still done by humans).
But as for badly written ... I feel a little balance is needed. In particular, I feel it's important to caution against a common hyper-sensitivity to language problems in publications.
The phrase "badly-written" is subjective. Sure, the readability of the paper is an important aspect of the quality of the paper, and there is some minimum level of language quality that is a prerequisite, but that level can be artificially high for some academics.
The majority of research is published in English by non-native speakers. Many papers are primarily authored by students in their 20's/30's who might be quite new to English and to writing scientific works. Even certain native English speakers will struggle to structure a paper in such a way that it reads well (sometimes because they are still of the belief that things have to be complicated and difficult before they can be published, so they write in a complicated and difficult way).
As an example of hypersensitivity, I am a native English speaker and for a journal paper I was primary author of, I once had a reviewer complain that the paper was poorly written. His/her main complaint was that we were confusing the semantics of "that" vs. "which" in the paper, saying that mixing the two up is not up to the formal standard of English required for journals. Eventually I did actually manage to stop laughing, but as I picked myself up from the floor, I realised I'd have to "correct" it for the revision. Three hours of Ctrl+F'ing "that/which" in a 40 page journal paper (and even worse, fixing the resulting bad boxes and widows again) wiped the smile off my face.
I also find that students new to reviewing, particularly non-native speakers, tend to expect a very high standard of writing. For example, I assigned a workshop review to a student once that wanted to reject the paper, primarily due to having "several typos". These would take 5 minutes to fix and didn't affect the paper at all. I asked the student if he had had any problem reading the paper? He said he hadn't. Did he learn something from the paper? Well yes, X, Y and Z. Why is he rejecting the paper? Necessary has two 's's.
Yes, the quality of writing often sucks in published works, but I don't believe that a paper should be automatically rejected just because it could be labelled as "badly written".
The goal is to communicate ideas with good science/maths, not to give an exposition of English grammar and phrasing. The original versions of many important publications were almost indecipherable in their writing. Even if an idea is written in such a way that you have to spend a few more hours to understand it, the idea itself might influence you and many other people in a positive way for many years.
Yes such influential papers are rare, but there are many shades of grey in between black and white.
And think of all the raw brain-power we will be missing out on if we perpetuate a culture that implicitly discourages non-English speakers from publishing!
In any case, for journals, I would tend to blame poor copy-editing and typesetting from the publishers. Most journals employ professional technical writers whose job is to avoid this situation. (I don't envy them their job, but still.)