Both Mary and Joseph were in the bloodline of David. Since Joseph was not the physical father, to fulfill the prophecy that the Messiah would be from the line of David, Mary was along that line too. Joseph and Mary were not close relatives so their marriage was not forbidden.
That has to be it. I’ve not thought about it for some time. And I googled that “cousin” is only used in the KJV; I’ve got 3 or 4 different translations and can’t work from them all from memory.