Social security and social security membership are not regulated by tax rules or tax agreements, but by social security rules and social security agreements.
The basic principle is that you may only be covered by the social security legislation of one country at a time, thus avoiding paying social security contributions in several countries simultaneously. Which country you contribute to must be determined specifically.
Social security affiliation should be clarified in light of the relocation.