even if you're removing principal, it's a loan so you begin paying it back immediately. In 3 years you should have paid back almost half of it, so still why is the cost $500K so extreme?
The money you spend paying off the principal and interest on the loan is money that you could have otherwise used for retirement contributions if you hadn't taken out the loan. At the end of 6 years, your account is ($30K + loan interest + missed growth) lower than it would have been if you had directed all of your money toward retirement contributions instead of taking out the loan.
We cannot know that value exactly, because we don't know how much the stock market will grow during the 6 year period. For the sake of the argument, let's say it's $50K. A couple more assumptions: say you are 40 years from retirement now, and that we expect a 6.5% real return on the stock market (which is the historical median long-term return).
The calculation for the opportunity cost would be:
$50K * (1.065^34) = $425K
So you can see it is in the same ballpark as their result. With slight changes in assumptions you could get $500K as the result.
Now there is a pretty big asterisk I want to put on this number (aside from the fact that it is based on assumptions): It is *only* based on the change in your retirement account. It does not account for the equity in the house, or any differences in mortgage / property tax versus rent. Let's assume that your housing related costs are equal whether your rent or buy to simply things. That is a very important assumption, so you should adjust your thinking based on the relative cost of rent vs mortgage + property tax + maintenance costs in your area.
Houses have historically appreciated at a rate of 1%. If we use the standard 20% downpayment, then a $30K downpayment would equate to a $150K house (ignoring closing costs). Its value after 40 years is:
$150K * (1.01^40) = $223K.
Plus you will not have had to pay your mortgage for the last 10 years. Let's say that amounts to $77K to bring the "buy a house" option up to a round $300K.
So now the difference using my calculations is $425K vs $300K, which is not quite so big as before. And with the house option, you can continue living in the house in retirement. So it's not like it is a slam dunk argument to say that you shouldn't buy the house. And there are a lot of simplifying assumptions being made here that could shift the calculus either way. The point I would make is that there are a lot of people out there who believe that buying a house is a no-brainer financial decision that is guaranteed to save you lots of money in the long run. That is not true. It is entirely possible that it will be a breakeven decision or that you will even lose money. Therefore, I believe that the decision about whether or not to buy vs rent is something you should do based on lifestyle considerations rather than financial ones.