networksetup -listpreferredwirelessnetworks en0
find your wifi network you want to change
Preferred networks on en0:
Banana
CafeWifi
MyPhoneHotspot
Remove the network first with
networksetup -removepreferredwirelessnetwork en0 WiFiName
Then add it back with a higher index value (index starts at 0)
networksetup -addpreferredwirelessnetworkatindex en0 MyPhoneHotspot 0 WPA3
You can check if it should be WPA2 or WPA3 by going into your system settings > wifi > advanced