Obviously it’s legal. Will someone make a law against it in the future? They’ll try, but it won’t work and most proposals I’ve heard (such as restricting foreign buyers) are unconstitutional. The only possible path would be to tax non-owner occupied homes at a higher rate, which is possible but likely also won’t happen.