You normally should purchase insurance in the state where your vehicle is registered, driven and garaged in. Many states Department of Motor Vehicles require you purchase insurance from an insurance company licensed in that state.
States have varying laws so some may have legal issues with you being in one state and insuring a vehicle in another. Insurance company guidelines also differ so if you would want to insure a car that is going to reside in a different state you would need to check to make sure that the state laws allowed this as well as the insurance company's guidelines find it acceptable.
There are situations in which it is usually not a problem. These circumstances may include things such as going to college out of state, being in the military and stationed outside of your home state or perhaps having a car garaged at your vacation home in a different state.
If you want to insure a vehicle in another state and want to know about that state's insurance laws regarding your specific situation, contact that state's insurance regulator.
Most state's Department of Insurance will tell you that the single most important thing you can do to protect yourself from a claim denial is to, make certain that all of the information you provide your insurance company is complete and accurate. So if you are trying to buy auto insurance from out of state you will need to explain the reason and situation with the insurance carrier so that you are not found later to have misrepresented any of the facts when purchasing the policy.