There's actually two very good reasons for it. They're not really related to research though there are good reasons for that, and I guess I'll get to that after the main reasons, aside from a strictly ethical viewpoint which not everyone will share.
It's stress.
Let's go with the economics first. Most farmers don't have access to expensive lab equipment. They have no real way of measuring stress except when it is acute, like say shock from a big change in environment. However, by far the more costly form of stress is chronic. Chronic is when many factors build up over long periods of time. Denying animals range of movement, keeping them confined in large social groups, not giving them clean conditions. These are all factors which lead to chronic stress.
When the animals are stressed, they do not grow as well. The conversion of feed into body mass goes down, it may even require antibiotics as a therapeutic in their diets to bring the feed conversion ratio back up. But even still, it will not be as efficient as if the whole problem had been avoided in the first place.
So, from an economic perspective, it is in the farmers best interest to keep their animals as healthy as possible. Wasted feed, anti-biotics, all cost money, a lot of money. The temptation by farmers to push the envelope and grow as much as they can is actually less efficient, and will adversely affect the bottom line.
The second is health related. I already explained how stress is bad for the animals, but it's also bad for us as consumers. When an animal is stressed, their immune system is compromised. Therapeutic levels of anti-biotics in some cases may not be enough to avoid disease, even from normally ubiquitous pathogens. That poses a direct threat to food safety and security.
Diseased animals in the food chain can bring outbreaks of dangerous disease to humans. Think bird flu. Why do you think so many cases are in SE Asia? It's because they don't have proper husbandry techniques, and insufficient codified animal welfare laws. Food security is also at risk. Maybe the pathogen doesn't effect us, but instead destroys entire herds of animals. Then what do we do? Grain reserves are at all time lows. We'd be in one helluva mess.
So there's two reasons. We've already implemented them here, but we can't watch all farms at all times. Remember Bovine spongiform encephalitis? People still try to dodge the rules for pursuing profits, without realizing the harm they are actually doing.
Even for research purposes their are very good reasons. How do you think stress might skew results in laboratory settings? Any investigation should always seek to avoid confounding variables, and stress is definitely one of them, unless you're researching stress responses.
Great argument! OK, I see your point and I'll agree with you (provided your argument is based on evidence). I admit I don't know a lot about this subject.
In the case of rats then I suppose it would be a good idea to give them free range if they were being used as food, but it would be ridiculous to give them such range in a city; in terms of, that we have the historical example of Europe and the plague to draw from. Some rats in a city is a good idea but too many is dangerous. I don't see any reason to be ethical when exterminating them; obviously poisoning them and so forth isn't a good idea though.
And I still don't see any reason we should hamper science so some animals can be happy.
The fact is that a species has two avenues for survival right now: they should either taste good or have another kind of symbiotic relation with us. A good one is for biodiversity and so wild animals should, to a certain extent, be protected.