Ancient Athenian military ships had names, but exactly who named them and why they were named what they were named is not really clear. Some had names that appear to be propagandistic like "freedom," some appear to be associated with certain families, others seem to refer to the shipbuilders other achievements. It is likely that ships were named by the people who financed them and for them, it was a public governmental position. They wanted a name that people would remember, that people would associate with them or their families (so that when it was time for election to a more powerful/lucrative post, the voters would recognize them), and that would reflect well on their values or that of the city.
I'm not a hundred percent certain that this is the absolute oldest origin of the tradition, but it's the oldest example I know.