If you're selling your house, don't cancel until after closing. Even if you're not living in the house, you may still be liable for anything that happens to it or on the property. After closing, you can cancel your policy. Your mortgage company won't do it for you.
If you're switching providers, wait until your new policy is in effect. It's helpful to avoid a gap in coverage.