Why is it that authors will use fragments in writing to emulate speech, but it is considered grammatically incorrect?
As mentioned in Sentence Fragments
You may have noticed that newspaper and magazine journalists often use a dependent clause as a separate sentence when it follows clearly from the preceding main clause, as in:.
The current city policy on housing is incomplete as it stands. Which is why we believe the proposed amendments should be passed.
This is a conventional journalistic practice, often used for emphasis.
For academic writing and other more formal writing situations, however, you should avoid such journalistic fragment sentences.
Fragments are grammatically incorrect, since they:
are incomplete sentences. Usually, fragments are pieces of sentences that have become disconnected from the main clause.
Some fragments [...] are written as main clauses but lack a subject or main verb
It depends on what you mean by grammatically incorrect. Sentence fragments are not part of formal English, but formal English is only used in certain specific areas, such as professional correspondence or scholarly papers.
Outside of those areas, sentence fragments are common. So long as the audience understands the point, there's no reason to frown on them.
We don't speak formal English when we talk in our day-to-day lives. Therefore, it makes sense that novels will use sentence fragments when emulating speech, as you said.
It's also worth noting, I think, that some sentences that appear to be fragments are actually examples of elliptical construction. For example, the sentences "Fire!" and "Two tickets, please," convey complete ideas, even though they've left out some words. They're not fragments.
Richard Nordquist, at ThoughtCo, gives a balanced overview on the use of sentence fragments.
Most writing handbooks insist that incomplete sentences--or fragments--are errors that need to be corrected. As Toby Fulwiler and Alan Hayakawa say in The Blair Handbook (Prentice Hall, 2003), "The problem with a fragment is its incompleteness. A sentence expresses a complete idea, but a fragment neglects to tell the reader either what it is about (the subject) or what happened (the verb)" (p. 464).
In formal writing, the proscription against using fragments often makes good sense.
But not always. In both fiction and nonfiction, the sentence fragment may be used deliberately to create a variety of powerful effects.
Midway through J. M. Coetzee's novel Disgrace (Secker & Warburg, 1999), the main character experiences shock as the result of a brutal attack at his daughter's house. After the intruders leave, he attempts to come to terms with what has just occurred:
' It happens every day, every hour, every minute, he tells himself, in every quarter of the country. Count yourself lucky to have escaped with your life. Count yourself lucky not to be a prisoner in the car at this moment, speeding away, or at the bottom of a donga with a bullet in your head. Count Lucy lucky too. Above all Lucy.
'A risk to own anything: a car, a pair of shoes, a packet of cigarettes. Not enough to go around, not enough cars, shoes, cigarettes. Too many people, too few things. What there is must go into circulation, so that everyone can have a chance to be happy for a day. That is the theory; hold to this theory and to the comforts of theory. Not human evil, just a vast circulatory system, to whose workings pity and terror are irrelevant. That is how one must see life in this country: in its schematic aspect. Otherwise one could go mad. Cars, shoes; women too. There must be some niche in the system for women and what happens to them.'
In this passage, the fragments (in italics) reflect the character's efforts to make sense of the harsh, disruptive experience. The sense of incompleteness conveyed by the fragments is deliberate and quite effective.
... [there follow other lengthy examples] ...
Fragments and Crots
Different as these passages are, they illustrate a common point: fragments aren't inherently bad. Though a strictly prescriptive grammarian might insist that all fragments are demons waiting to be exorcised, professional writers have looked more kindly on these ragged bits and pieces of prose. And they have found some imaginative ways to use fragments effectively.