>> You buy a house for $400K and take out a loan of $300K using your $400K home as collateral. There is no gain here
Correct. You have a $400K asset and a $300K liability giving you $100K in equity.
>> Later, you want to refinance. Your home is now worth $600K, and
Nope, no "and". Before you even consider refinancing, you now have an unrealized gain. You have a $600K asset and a $300K liability giving you $300K in equity for an unrealized capital gain of $200K. Whether you take out a new loan or not, your net worth has increased $200K.
>> and you'd like to pay off your existing mortgage and take a new loan out for $500K. This should be considered income! Your net worth has suddenly gained +$200K
No, your net worth increased when the value of the house went up, not when you took out the loan. The loan is not income.
>> and you have realized the gain
No, the gain is still unrealized. You have a $600K asset (the house), a $200K asset (cash out from the refi) and a $500K liability (the new loan) giving you equity of $300K. You have not realized the capital gain. You have not made any income.
What you are trying to do is to use a refi as a trigger for taxing unrealized capital gains.