There are actually quite a few reasons why sedans stuck around.
One is separation of the passenger cabin from the cargo area. More than once I've accidentally bonked someone in the head putting something in the hatch or have had a dog escape because they managed to leap over the seat and get out through the open hatch. It's also easier to hide valuables in the trunk, as there's no indication anything's in there unlike the open rear deck of a hatchback you can see through the windows.
Another is lower center of gravity. There's not a large chunk of metal and glass above the beltline. This helps handling characteristics and makes it easier to engineer predictable patterns for the suspension. It also helps tire wear as there's less lateral force on the sidewall from the lowered center of gravity.
There's also the structural rigidity. Sedans have a slightly higher structural rigidity to them than hatchbacks due to the three box shape creating cross bracing. It makes it easier to engineer them to survive a crash without harming the occupants.
And lastly there's aerodynamics. Many hatchback designs in the modern era are extremely rounded for stylistic reasons. This is terrible for aerodynamic efficiency compared to a proper Kammback rear design. A sedan with a properly designed rear windshield and trunk actually has far less parasitic drag because it creates a much smaller area of low pressure air directly at the farthest rear edge of the vehicle. Unless you drive a Ford Fiesta sedan, in which case you're getting the worst of everything. If you've ever seen those monstrosities that BMW calls an "X5 Coupe" this is them trying and failing to apply the Kammback aerodynamics of a modern sedan to an SUV.
> More than once I've accidentally bonked someone in the head putting something in the hatch or have had a dog escape because they managed to leap over the seat and get out through the open hatch.
There a basic nets and if one is extreme cages which separate the boot from the second row.
> It's also easier to hide valuables in the trunk, as there's no indication anything's in there unlike the open rear deck of a hatchback you can see through the windows.
Pretty much every hatchback I've seen in the last 20 years here in Europe has a removable cover.
Hatchback, universal, minivan, suvs are much more practical.