By definition a stun gun is a non-lethal device used to only immobilize an attacker. However some states do regulate them and although in most they are considered legal, some specify certain conditions that need to be observed. Such is the case of states like Virginia, Florida and California where you can legally own a stun gun or taser unless you have been previously convicted of a felony.
Other states like Pennsylvania, Michigan and Illinois regulate these by allowing anyone who has a permit for firearms to possess them.
Although a minority, some states do consider them to be illegal, such is the case with New York and New Jersey.
That being said, the best advice we can give you is to consult your local authorities before you actually purchase a stun gun or taser. Even if you are certain it is legal to own and carry one, there is always a chance of you having to observe certain conditions to use them.
Please check stun gun laws for the area where you live.