Thoughts? Does my analysis miss anything?

Yep, like AJ said, in the no-mortgage scenario, you didn't account for the $477 in monthly income that you would be required to have in order to pay the mortgage in the mortgage scenario. In the no-mortgage scenario, you would still have that income, and should assume that money gets invested every month. Given those assumptions, if the mortgage rate is equal to your expected investment return, then there is no difference. With a mortgage at 4%, you lose $71,870 in interest payments, and without a mortgage, you lose $71,870 in gains if you had left that money invested at 4%.

You can try it out in spreadsheet-math. We really want to see what your investment account total is at the end to compare. The formula is:

=FV(Rate, Number of periods, Amount added per period, Starting Value)

Our period will be months, so there are 30*12=360 of those, and our rate is also per-period, so we divide 4% by 12.

In the no-mortgage scenario, we drain $100k out of our account at the beginning, leaving us with $0, and adding it back at $477/mo:

FV(.04/12, 360, $477, $0)

In the mortgage scenario, we start with $100k in the account, but never add anything, since that money is going to pay the mortgage:

FV(.04/12, 360, $0, $100000)

Both come to the exact same result, $331,349 (actually the first is slightly off, because the mortgage payment is really $477.4153)

I don't know what most people are actually referring to when they use a predicted 7% (or 5%, or whatever) return rate in the stock market, but I assume it's a Compound Annual Growth Rate, in which case the compounding is already taken into account. That means you don't get any "bonus" from the power of compounding, because it's already baked into the prediction.