Let's say one is a permanent resident of Canada (and is not a North American national) and is therefore eligible for a NEXUS card. If they apply and receive a card but then move out of Canada (say, to the US), would the NEXUS continue to be valid? And if so, would it continue to be valid when the person in question loses their Canadian residency due to not living there for too long?
You have a duty to report to the NEXUS enrolment office any material changes in your circumstances. https://www.cbsa-asfc.gc.ca/prog/nexus/contact-coordonnees-eng.html is a list of material changes. Strangely, residence isn't listed but my strong instinct is that it is a material change.
Personally, I would report the residency change, and let the enrolment centre decide if you are still eligible for NEXUS. My strong instinct is that your NEXUS card would remain valid but you would not be allowed to renew it - I'd invite anyone with experience in this direction to add a comment. Note - https://www.cbp.gov/travel/trusted-traveler-programs/nexus/nexus-eligibility - that US permanent residence is also an eligibility criterion, so you'd have to disclose this but will be allowed to keep NEXUS (and to renew it), absent any other contraindications.
If in doubt, report - if they accept your change, you're good to go and won't risk your future eligibility for NEXUS, should you return to Canada or the U.S.
As long as you satisfy all requirements of Nexus it won't become invalidated. For e.g., if you lose your Canadian PR status but now you're a US PR/Citizen or Canadian citizen you still satisfy the Nexus requirements. The Nexus requirement isn't specifically tied to the eligibility criteria that you specified when you first applied. Circumstances change and as long as you report them to the Nexus authorities in time and you are still eligible, you should be fine.