You don't. You merely have to earn 40 work credits to get retirement benefits - doesn't matter when you've earned them. When it comes to a retirement benefit they use your high 35 years of earnings. If you fail to have 35 years of earnings they will use zero years to make up 35 years - that will result in a pretty low benefit amount.
As for survivor benefits how many credits are needed is determined by age at time of death. Again it doesn't matter when you earned them.
However, disability benefits are different. The SS disability benefit is meant to partially replace the loss of CURRENT earnings. How many work credits you need and when you need to have earned them is also determined by a person's age at time of disability. It can be as little as earning 6 credits out of the 12 quarters before age 22 up to more than 20 credits most of which must have been earned within 5 years out of the 10 before becoming disabled if age 31 or older. That's why, when a person stops working, there is such a thing called date last insured. What that means in terms of processing a disability claim is that no evidence after date last insured is considered in making the disability decision. For a person who has worked steadily all their lives, date last insured is normally 5 years after the date they stopped working.
I was a SS claims rep for 32 yrs.