Elizabeth was from the priestly tribe of Aaron (Luke 1:5), Mary, from the tribe of Judah (Luke 1:36).
Though in the Bible people belong to their father’s tribe, they still recognized their maternal relatives (mother’s family). This means that since Elizabeth’s father was from Levi, and Mary’s father from Judah, both Elizabeth and Mary had mothers who were related (possibly sisters), so they could both have been first cousins or fourth cousins.