Many years ago getting hired as a cop in larger cities was a political appointment. You went to see the alderman or city councilman — back then there were no female politicians — and you "applied" for a city job. Each district had a set number of public jobs to dole out. You signed your name in a book. If your family was with the correct political party, you had been a voter and, of course, you would be forever grateful to the councilman, you just might get the job as a cop, firefighter or city worker.
This was the way it was and it's easy to see how corruption and other ills infiltrated governmental work. Under this system, here's te baseline for residency requirements — you and your family were voters; you would continue to support the politician that gave you the job; you would provide electorate security.
Even today, financial motives persist. Larger cities (especially in the Northeast) have some form of "earned income tax." Your income is reported (by your employer or via your tax return) to the locale where you live. You then pay a tax on your earned income that goes into city coffers. Why? More people are renting, and they need to shore up the tax base.
This is the thumbnail version. Now, if you're going to pay big bucks to a police officer or firefighter, it only makes sense to force them to live in the city, so you can gain more return on tax dollars. Why let the suburbs take all that tax money?
This is never the real reason for residency, according to city governments. They claim that if you live in the city you'll be a "super resident." You'll take pride in your hometown and become more involved. This was touted in the late 1980s along with community policing.