My understanding is that they were brought to the Yorkshire and Lancashire areas of England by poor Scottish immigrants and the breed was refined in these areas and given the name Yorkshire terrier.
The immigrants were poor and the land owners allowed them to tenant farm with certain conditions. They were allowed to own only dogs that would fit through a seven inch hoop, this assured they could not hunt large game. The immigrants typically worked as day laborers and in addition to coal mines they worked mowing fields, where their rat killers were very welcome to come and hunt. They would dig pits for the rats to jump into before mowing the fields and once the days work was done they would wager on how quickly a given dog could kill all of the rats in a pit.
The genetic experts of the day were horse breeders. Carriages owned by the affluent would be pulled by more than one horse and the best breeders produced matched sets of horses to pull carriages. The day laborers were hired to clean stalls and do manual labor but were also exposed to the genetic expertise of the horse breeders and they applied what they learned to their beloved breed. The Yorkie was very quickly refined into a valued companion, one that would guard the families food supplies from rats with deadly efficiency and still be beautiful at the end of a leash for an afternoon stroll.
I don't hold this out as fact, it's just bit's and pieces I have picked up reading about the history of the breed. JMHO