First, as others have stated, never buy the cruise line's insurance policy. Usually costs more, does not provide as good a coverage as independent, and does not provide as much coverage as an independent policy. For example, some cruise lines' policies do not cover independent air reservations.
If you purchase the coverage at the time you make your non-refundable deposit, then your deposit will be covered should you need to cancel for a covered reason at any time.
If you made a refundable deposit, then you don't need to purchase the insurance until your final payment is due in order to be covered for pre-existing conditions. You can still purchase the insurance after that date, but you won't be covered for pre-existing conditions. Some policies will also exclude other coverages such as bankruptcy and terrorist attacks.
Talk to your agent and they can explain all the various options available to you.