Is disfellowshipping a legal procedure?
Your relationship with your local congregation is a voluntary association consensual to both parties. You have the right to disassociate yourself from the congregation. The congregation also has the right to separate from you at the descretion of ecclesiastical tribunal.
Like is there something I can use to prevent this from happening to me if it does happen.
Jehovah's Witnesses are legally organized as a congregational church. Your relationship is with the congregation you've voluntarily affliated yourself with and only with that congregation.
You do not have a relationship with any other congregation of Jehovah's Witnesses and neither do you have a relationship with any of the JW parent organizations.
The best advice I can think of is simply to move away.