A law that provides many of these protections is called the Servicemembers Civil Relief Act (SCRA). This law was made to help protect members of the military and their family who may have trouble with financial and legal issues because of military service.
This law allows a service member that has to move due to military orders to terminate a lease early without penalty. This includes activated reservist, new service members, current active duty deploying or PCS orders.
The SCRA does not stop the landlord from evicting you, but it does demand that he or she go through the court system to do it. However, if your landlord does go to court to try and evict you, the SCRA has some other protections that you may want to use. The SCRA requires landlords, in all states, to obtain a court order before evicting a servicemember or dependents during a time of active duty service. See 50 U.S.C. App. §331 of the Servicemembers Civil Relief Act.
The landlord must refund the security deposit (minus any damages) within 30 days of the date the lease was lawfully terminated under the SCRA, 50 U.S.C. App. §535.