You do not have to pay Massachusetts income tax on what you earn in Massachusetts if you are the spouse of a nonresident service member and you are only here because of their military orders.
There is nothing to apply for up front. Claim the exemption on your Massachusetts return, and give your employer your home state residency information so Massachusetts tax is not withheld.
Your marriage certificate, the service member’s orders assigning them to Massachusetts, and proof that you and the service member are residents of the same other state or territory.