Grammar is bad and doing A-level English Watch
(1) You read lots of books which are well written. As you read more, you get a better understanding of how words go together, and you can see when you're supposed to use more advanced punctuation. Clauses, semi-colons, rule of three - all these can be seen in literature and so you learn by example.
(2) You don't read books, your only source of written material is online or something else. You don't have any way to properly learn how English is put together in writing apart from lessons which may not make sense to you, depending on the type of person you are.
Of course, type (2) does seem far-fetched, but you could say that it can be diluted to a similar result though not as extreme.
If you read well written literature, you can see examples of grammar in use. People tend to learn by example, so if you immerse yourself in a book you immerse yourself in the English language (or any language) so you become better at grammar. This method doesn't help you necessarily understand all the components of grammar, but it does help you get a feel for it - an intuition.
Also, I'm talking about any kind of literature, not specifically grammar books if that was what you were thinking.