I was reading the Wikipedia article on Henri Nestlé. It claims:
The Nestle family tree began with three brothers (thus the three young birds in the nest being fed by their mother on the family coat of arms) from Mindersbach, called Hans, Heinrich, and Samuel Nestlin. The father of these three sons was born circa 1495. Hans, the eldest, was born in 1520 and had a son with the same name, who later became mayor of Nagold. His son Ulrich was a barber and his fifth son was the first glazier in the family. For over five generations, this profession was passed down from father to son. Additionally, the Nestles provided a number of mayors for the boroughs of Dornstetten, Freudenstadt, Nagold, and Sulz am Neckar.[citation needed]
So perhaps we shouldn't take this 100% at face value because of the "citation needed".
However, were medieval and early modern cities "republics"? Crusader Kings II and Crusader Kings III portrays them as "republics" because their mayors were chosen by their voters - but is this accurate?
Also, CK2 and CK3 portrays city mayors as being elected for life. Is this accurate?
Provided that there is no single and comprehensive answer for the entire geographical and temporal span of the Middle Ages, there are some examples that can be provided which may shed some light on the matter.
Mayors in the Middle Ages were elective offices as far as I am aware, especially in locations such as Italy and France. Not all cities appear to have elected mayors however, and a link between their presence and a form of higher authority seems to be present quite often. Citing southern Italian cities during the Angevin and Aragonese periods (1266-1497 ca.), cities both part of the royal demesne (a direct property of the ruler) and associated with feudal powers appear to have elected their mayors (often, a city would elect several, not just one) without a direct decision by the sovereign. We cannot rule out some sort of influence by groups of interest, but there is so far no source claiming that the king directly appointed a mayor in his demesne cities. Not even vassals with cities in their domains seem to have done so.
Mayors were mostly elected among the middle and upper urban classes, containing mostly craftsmen, merchants, law experts (notaries, judges, lawyers etc.) and the aristocracy (a thing in Italian cities and city-states is that the landed nobility could live within cities instead of their rural possessions). Taking as an example the city of Capua, the second most important city in the kingdom of Naples, it had a first council of six mayors named "the six elected ones", elected among the aforementioned social groups and each mayor stayed in office for four months. Alongside them there was the Council of the Forty, whose members were both elected and picked personally by the six mayors. There were also another dozen of public offices, like the mastrodatti, the official notary charged with the writing and archiving of the public acts and deeds resulting from the city's councils, or the city's official lawyer meant to represent the community in court processes.
Another important city in the kingdom of Naples, Sessa, was a direct possession of the king and it elected three mayors as of 1464 and most likely even before. They were selected by having a child no older than seven extracting a wax ball containing a piece of paper with a name written on it. Said person was to be mayor that year. There were three sacks with names in them, one for each social group eligible ("gentlemen", aristocrats or people possessing a university degree, "citiziens" most likely merchants, craftsmen and the like, and a third sack whose reference is not specified). Said procedure was in place also to elect the three market officials and the eighteen members of the city council (six from each sack) who would assist the mayors. Other offices, like the aforementioned mastrodatti, were chosen by procurement.
There were, however, in the case of the kingdom of Naples, royally appointed officers who would represent the crown within a city's inner politics. The royal captain was one of these. In Capua for example, he reprensented the king and was the head of the local court of justice. He maintained public order and was allowed to pass sentences of what is known as first degree justice (corporal punishment, fines but not capital ones) and organized the military aspects of the city's territory and also gathered informations for the king while placing the city council under surveillance. He held his own court within the city with officers appointed by the king. A similar thing was present in the city of Sessa. Mayors of demesne cities also appeared in some of the general assemblies summoned by the Aragonese kings over the course of their lives as political representants of the most important powers of the realm alongside the very powerful vassals of the king.
Royal captains, however, were not meant to curb the city's political power, rather, to act as a counterbalance. It was rare for a captain to actively veto or hinder the mayors' decisions, most often because the public powers they possessed were split between civil offices and royal offices (and we have plenty of administrative and judicial documents explaining the different areas of competence of these officials, mostly pertaining taxation and justice). They were there also to negotiate between the communities and the central powers, like when the city of Sessa asked and obtained a complete exemption from taxes and duty taxes during the weekly market occurring on thursdays, or the possibility for their citiziens to be judged only by the royal tribunal present in Sessa and nowhere else.
As a last note, mayors and other officials, like the public tax collectors or the private individuals holding tax duty office by procurement, had their conduct put under a very in-depth scrutiny by either the newly appointed officials or by the royal accountants of the Camera della Sommaria, the kingdom's highest authority in financial and judicial matters in order to prevent misconduct, fund embezzlement or any other form of crime.
CK2 and CK3 do a good job in my opinion of providing an overview of Medieval politics, but the "republic" tag attached to all cities is quite misleading in my opinion. However, I understand that gameplay-wise having characters change every few months can be annoying (especially if they hold important offices in your court).
I hope this overview helps your inquiry.
Sources:
Senatore, F. 2018, Una città, il Regno: istituzioni e società a Capua nel XV secolo, Istituto Storico per il Medioevo;
Senatore, F., Scarton E. 2018, Parlamenti generali a Napoli in età aragonese, FedOA Press, Firenze;
Broccoli, A. a cura di, 1889-90, “Codice municipale sessano” in “Archivio Storico Campano, compilato da alcuni autori di storia e letteratura patria”, Stabilimento Tipografico Sociale, Caserta, vol. I, 2-3;