Someone can come from a tribe different from one cousin because one cousin mother or father as the case may be might come from a different tribe. Therefore, there is a possibility that Mary came from the tribe of Juda. There is nowhere in the Bible that it was written that Mary is not from the tribe of Judah. Scripture was written by the inspiration of the Holy Spirit. So, we should not doubt the words of God. The word of God said Jesus came from the tribe of Judah.
Hebrews 7:14 For it is evident that our Lord sprang out of Juda; of which tribe Moses spake nothing concerning priesthood.