There are a lot of "Mexican" things in the US that aren't really Mexican - or which developed in border areas for the benefit of richer clients. Much of Mexican food is this way.
I just spent a few minutes poking around the internet for stories about where this phrase came from. It's not a common Mexican phrase. The stories I found ranged from poor workers living in houses that belonged to their rich Spanish overlord, to indigenous people thinking that the Spanish settlers were gods, or to simple explanations stemming from Mexican hospitality. Right or wrong, it's this last notion which lives on in the conventional thinking today.
I'm persuaded by the following, more practical explanation. We Americans wanted to invent a fancy-sounding foreign phrase to use when we're welcoming people into our homes, and "mi casa es tu casa" is much easier to say than the Welsh alternative: 'Fy nghartref yw dy gartref'.