So the legitimacy of a child does not depend on God but on what the parents believe?
They are legitimate if the parents never suspect the marriage is invalid, but if they later believe the marriage is invalid, then suddenly the children move from legitimate to bastard?
What is your source on this??
What if the parents believe the marriage is invalid but it is valid are the children still bastards based on their parents beliefs?
Do you really think that God cares about the "legitimacy" of a child? I think, in God's eyes, all children are "legitimate".
As an aside, the concept of "legitimacy" doesn't carry any sort of disability in current canon law. It's mentioned only in passing IIRC, and that mention is only there for the sake of inheritance law in countries where civil divorce doesn't exist.