Can you divorce in Canada when you are not a resident of Canada?

In general, yes.

Note, this question may stem from a legal gap, where previously marriages performed in Canada to non-residents whose marriages might not be recognized in their state of residence were not definitely recognized in Canada (eg, marriage of a woman in the US to a woman in Britain). That has since been rectified: all marriages performed in Canada are now legally recognized in Canada.