We need pain to encourage us to rest the affected part while it heals, but there are times when this is so severe and long lasting that it has the reverse effect.
To put pain in context, all animals, including humans, have evolved to deal with massive pain in the short term, as would be expected when evading predators, but there has not been enough selection pressure for us, or most of our animals to deal with severe long term pain.
Long term severe pain leads to slower recoveries and increased morbidity and mortality after surgery. Surprisingly this has only recently been recognised.
Another surprising thing about pain management is that as late as the 1987 babies in America were routinely operated on without anaesthetic because it was thought they could not feel pain. To some extent this still goes on with regards to circumcision of people and tail docking and castration of farm animals; younger beings are not supposed to feel pain as much despite there being plenty of evidence to the contrary.
Now it is recognised that pain relief is a vital part of managing illness and injury in people and animals and not to do anything about it is negligent and cruel.
There are two main groups of pain killers: centrally-acting and anti-inflammatory.
Centrally-acting painkillers bind to the nerves in the brain that interpret pain, and are usually derived from opium in one form or another. The current thinking is that brains produce their own painkillers, which are referred to as endorphins (a homologation of the words endogenous and morphine). These are thought to be released in massive amounts during periods of acute injury, which is why people report not feeling the pain of shark bites for example, until sometime later.
However, what happens is that the supply of endorphins runs down after a while and the pain returns, which is why we supplement the endorphins with exogenous opiates and other pain relieving medications when the pain is severe enough to warrant it, and/or is serving no function. Rheumatoid arthritis is a good example of pain being unremitting and serving little or no function. In pets, the pain after surgery is another reason for using this type of painkillers, which is why we give opiates before the surgery, as well as injecting local anaesthetic into the wound at the time of surgery.
The second type of pain killers is to give anti-inflammatory drugs. Like pain, inflammation is there for a reason, to increase the blood supply and encourage healing, and dampening this down does delay healing. In most cases this is negligible, but can be significant in the case of corticosteroids. This is why corticosteroids tend to be reserved for special pain relief cases, like spinal pain, or arthritis in very old animals.
Also, many of the non-steroidal drugs (NSAIDs) cause stomach ulceration and kidney damage through causing small blood vessels to constrict. Stomach ulceration is often manifests as vomiting, and even if this doesn't occur, it can leave the animal or person feeling nauseous.
Local anaesthetics do work well, but usually only for a short period, but this can help with the initial very painful period after the anaesthetic wears off.