Spanish residency applies to the person, not the property, so if the boat is not for commercial use, you can register your future boat under the Belgian flag and leave it in Spain for as long as you want.
You won’t be subject to Spanish legislation unless you are using the boat for professional activities. The seller will need to provide you with all the documents for the flag change, such as the bill of sale, cancellation of the previous flag, European VAT clearance, etc.
A broker should easily handle these procedures and provide you with all the necessary documents for obtaining a Belgian flag (personally, for peace of mind, I would go through a broker, even if it incurs a few fees).
If it’s a Belgian flag and you’re Belgian, I wouldn’t choose another flag, but if it’s a Belgian flag and you’re French, then switch it to the French flag.