In the 10th century, as a gesture of friendship, a Scottish king was given land in London with the provision that he build a castle and live in it a portion of each year.
Seven centuries later, when England and Scotland became united under a common ruler, the land was turned over to London authorities. It was divided into Greater and Middle Scotland Yard, and the London police took up residence there in 1829.
Today, Scotland Yard refers to both the metropolitan police that's based there, as well as its many local stations.