These are two separate questions. The first one is technical (how animals are treated) and the second one is social, legal and artistic (why is the presentation of cruelty to animals allowed).
The answer to the first question is that, these days, animals are not treated badly (at least not in mainstream Hollywood films) and there are animal rights advocates on set making sure that is true. Though, as with any aspect of life, we can't really determine remotely the fealty of any given group of agents, only that they are credentialed, essentially, by the ASPCA, PETA or whomever.
So, even today, you still get the occasional controversy, as in A Dog's Purpose where a leaked-video went viral and caused a ruckus.
In the past, animals were certainly treated badly, even maimed or killed. (Probably not as routinely as you might think, as a trained animal is a valuable resource.) The "how" was simply "because people didn't care that much" though this is a little glib: A filmmaker had little option but to risk animal injury to achieve certain visuals, e.g., horses in a cavalry charge.
As for why, there is such a thing as freedom of expression, and that includes the freedom to express things that are uncomfortable, dangerous or tragic. For example, here's a documentary from 1920. As one of the commenters points out, one the scenes is reminiscent of elements in the recent Lord Of The Rings movies. These days CGI reduces (but does not eliminate) the risk.
Almost inevitably, any movie about a man and his horse are going to result in some sort of action scene which poses a danger to both man and horse. For example, George Miller's popular 1982 film, The Man From Snowy River.
Countless cats have been (and probably still are) scared for horror movie purposes, and I'm sure (especially on the lower budget end) it's still easier and cheaper to provoke an animal than to get a well-trained one that can "act".
For mere representation, without actual danger to the animals, such as a serial killer torturing animals, or boiling a bunny, well, freedom of expression even covers, though people are less inclined to support this today, the right of people to enjoy things that are morally reprehensible.
We get into the philosophy of human beings, but I think—even more than human abuse—animal abuse is generally presented as a horror-to-be-avoided, such as in the above (mocked, because I didn't want to put a picture of a bloody bunny in this post, even if faked) Fatal Attraction scene. Very few humans (as a percentage) enjoy abusing animals, even vicariously, and I think it's well-established that even using animal abuse as a representation of a terrible horror is risky—i.e., it can backfire in terms of audience appreciation.