A written, advance notice is required when an insurer is going to cancel (or "non-renew") a policy. If you got that notice in writing at least 45 days beforehand, then yes, the insurer can do this.
Often, the problem for homeowners is the timing. They simply don't have enough time to find contractors or do the work themselves. In such a case, you might be able to talk to your insurer and figure out a repair plan that will satisfy them. If not, you'd better start shopping for alternative coverage.
You might also ask your agent to talk the insurance company. There's no guarantee that the company will change its mind, but it might help.