They are synchronised over iCloud, so if you log in to iCloud the list of networks and their associated passwords are added to macOS.
How do Wi-Fi networks persist between installs?
They are synchronised over iCloud, so if you log in to iCloud the list of networks and their associated passwords are added to macOS.