> It sounds like a defined-benefits fund
The first key is that it isn't defined-benefits, in the sense that there is no account labeled "Bob Smith's Accumulated Retirement." Don't be disheartened though, because many Americans have the wrong idea too. [0 - See rant in footnote.]
In addition, the US has no constitutional barrier to protect it, the federal legislature can pass a regular law which completely rewrites the benefits however they like. It could be very unpopular, though.
> Can someone explain the legal structures [...]
It has grown a lot of bells and whistles over time, but at the core its formal original name of "Old-Age, Survivors, and Disability Insurance" is very informative.
* The premiums for coverage are collected as a tax on the working.
* Payout conditions broadly involve being alive and not able to earn enough to stay that way.
* If you pay in and then die young and healthy, you don't get anything. This is normal and intended, the same way that home fire insurance doesn't pay if your house is swept away by a tsunami.
* The program's surplus funds (from planned-for demographic shifts) is invested in bonds with the US government, meaning that there's an intra-governmental credit/debt going on, where OASDI/SS is the creditor and government-in-general is the debtor.
> [...] that make Social Security "run out"?
Most of the "run out" talk refers to a period of time where the invested surplus dwindles due to yet-more demographic shift, and cannot cover the difference between inflow and outflow. At that point one or both of these will have to happen:
(A) Congress passes a law increasing premiums/taxes on current workers
(B) Congress passes a law saying it's OK to pay less than the program did before.
Congress has been procrastinating on this for many decades.
__________
[0] I blame this on deliberate tactics by big-banks, and political groups ideologically opposed to the program. Private banks are unable to make big bucks offering a competing insurance plan, so instead they promote a false comparison. It goes like this:
1. They falsely assert that X% of the current surplus is somehow already exclusively "yours."
2. They claim that "your" money exists in a boring lame government retirement account which only invests in bonds. (Only half-true, in that the surplus is in bonds.)
3. They ask if you'd rather have the option of moving the money to a new account run by Big Bank, who is so much cooler will help you (for a modest fee) invest in stocks which go up much faster so "your" money will be zillions by the time you retire.