The rules are silent, so DM decision
The rules only specify what the conditions for targeting are when the spell is cast and do not cover cases where that condition changes after the fact.
The rules assume that the target is decided when the spell is cast and that the validity of that target does not change after that. However, there are obviously cases where that can occur (as pointed out by your question).
It is a DM's decision
As always in 5e, when the rules aren't clear or are silent, the DM must step in to make rulings to fill the gaps.
As a DM, it makes complete sense to allow the spell to be suppressed or dispelled once the target becomes invalid. However, since there a quite a variety of spells and targets it may make sense to evaluate each one on a case-by-case basis as they come up. This is not a case that happens very frequently at my table or any I've played at, but if it becomes enough of an issue, a DM may need to make a general ruling to keep the game running smoothly.
But, again, as this is not spelled out in the rules anywhere, it will have to be a DM call to decide what happens.
Jeremy Crawford states much the same in an opinion written on Twitter:
There's no rule governing what happens when a valid spell target temporarily becomes an invalid target. A good rule of thumb is that the spell is suppressed while the target is invalid.
How I have/would rule at my table
For Light/Darkness specifically, I would rule that the effect gets suppressed for as long as the lit thing is an invalid target. If they become a valid target within that time again, then they begin to light up again.
It doesn't make sense for the Light/Darkness to become detached from their original targets nor does it seem like the spell would necessarily be dispelled. Thus it seems like a very easy, and workable medium option.
I've ruled this way for similar spells a few times at my table and it made sense and it worked well and we really didn't think too hard about it honestly. I can see other ways of ruling potentially working as well, but this is the way I've done it.