Why won't anyone just answer the original question?
The question was not about opportunity cost or flexibility or family expenses. There are no right answers to any of those things and they all depend on individual circumstances.
I believe the answer to the question of whether paying off a 30-year mortgage in 15 years would cost the same amount as a 15-year mortgage of the same interest rate is yes but ONLY if you pay it off on the exact same schedule as your supposed 15-year. In reality, the answer is NO for two reasons: the amortization schedule; and the fact that the 30-year will always have a higher interest rate than the 15-year.
The way mortgages are amortized, the interest is paid first, essentially. For most people the majority of the monthly payment is interest for the first half of the loan's life. This is good for most people because, in reality, most mortgages only last a couple years after which people refinance or move and for those first couple years the majority of one's housing costs (interest) are tax deductible. It is arguable whether perpetuating this for one's entire life is wise... but that's the reality of most mortgages.
So, unless you pay off your 30-year on the exact same amortization schedule of your theoretical 15-year, you will pay more in interest. A common strategy people pursue is paying an extra monthly payment (or more) each year. By the time you get around to chipping away at your principal in that way, you will already have paid a lot more interest than you would have on a 15-year. And, really, if you can afford to substantially pay down principal in the first year or two of your mortgage, you probably should've borrowed less money to begin with.
In theory, IF the rates were the same (they're not) and IF you paid the 30 off every month in the EXACT same way as you would've paid a 15 (you won't) you will pay the same amount in the end. You have to decide if the flexibility is worth more to you than the cost savings.
For example: a 300k mortgage at 3.5% will have a monthly payment of ~$2150 for a 15-year and ~$1350 for a 30-year, both will start with ~$875/month of that being in interest (gradually declining with time).
What I think most people undervalue is the freedom and peace of mind that comes with a paid off or nearly paid off home... and 15 years is a lot more tangible than 30, plus a lot cheaper over all.
If you can afford a 15-year mortgage without putting too much stress on your budget, it is definitely the better option for financial security.
And be careful of the index fund opportunity cost advice. On average it may be a good idea when you look at the very long run, historically, but a lot of people get less than average returns depending on when they buy and what the market does in the short run. There is no certainty around what returns you will get from the stock market, but if you have a 30-year mortgage there is a lot of certainty around what you will owe every month for the next 30-years. Different mixes of investments make sense for different people, and most people would be wise to get some exposure to the stock market for its returns and liquidity. However, if someone's goal is borrowing more money for their house in order to invest more money in the stock market for their retirement, they would actually be better served in achieving security and independence 15 years sooner.