Used in this way, "flagship" is fundamentally a temporary designation; the flagship is wherever the admiral is flying his flag. However, admirals have always needed additional facilities; a meeting room large enough to hold all the captains of the fleet, and a place for the admiral's staff to make plans and draw up orders.
In the age of sailing ships, the flagship was typically a first-rate; the aft of one of the three decks would become the admiral's quarters and staff offices. This can be seen today on HMS Victory, the flagship of Admiral Nelson at the Battle of Trafalgar, now at Portsmouth, England.
In the 20th century, ships became large enough that most types could accommodate commander and staff, and during World War II admirals would often prefer a faster ship over the largest one. Increasing communications and computing requirements have resulted in the design of specialized command and control ships to serve as flagship.
As with so many other naval terms, flagship has crossed over into common parlance, where it means the most important or leading member of a group. It also come to be an adjective, as in the "flagship product" of a manufacturing company.