Here's how the Crusader Kings II Wiki describes the process of becoming a republic:
The decision to found a merchant republic requires a Large Market City and
the technology Trade Practices 1. Building the Large Market City requires
? Town Infrastructure 1. For players, it has the additional requirements of a
coastal capital and The Republic DLC, in order to ensure the resulting realm
In addition to upgrading your capital to a city, it creates a duchy-level title
(if needed) and creates family palaces for you and four vassals of different
Being a republic unlocks the convert to city decision for both you and
your direct vassals.
I assume by "upgrading your capital to a city" it means upgrading a tribal holding to a city holding. If your capital is a castle holding then I doubt the game would allow you to become a republic. It would probably break the game if it did. No other holdings would be upgraded automatically, but you should now be able to use the "Upgrade Tribal Settlements to City" decision to do so.
So your castles should remain as-is in your demesne, except as a Patrician you should longer have the -75% wrong holding type penalty.