2 – Like a ROTH IRA, contributions may be withdrawn at any time for any reason penalty free.
3 – Like a ROTH IRA, contributions are withdrawn before gains.
Withdrawals are
prorated between contributions and earnings. Also note that this tax credit
will be recaptured if you make a non-qualified withdrawal.
That all said, this could be a good deal if your time horizon is long enough and you don't expect to fill up your standard deduction during retirement otherwise.
Let's look at a comparison: you could invest $4,000 of after-tax money (worth $5,000 in a 529) into either your 529 or a taxable account. Suppose you hold the investment long enough for it to increase 5x in value.
529: initial value: $5,000. Final value: $25,000. Federal tax: 10% of $20,000 growth ($2,000). State tax: regular rate on the growth, plus $1,000 in recaptured credits. Amount left after tax: $22,000 minus any state tax on the growth.
Taxable account: initial value: $4,000. Final value: $20,000. Federal tax: 0% of $16,000 gain. State tax: maybe some capital gains? Amount left after tax: $20,000 minus any state taxes.
However if you have enough other retirement savings that you'll be exceeding the standard deduction anyway, you could add another $2,000 (minimum) to the federal tax bill, and the 529 doesn't look so great anymore by comparison.
How do you feel about taking a few classes during your retirement? If you sign up at a local community college at whatever level they consider to be a half-time student, whatever you pay for tuition plus reasonable food/housing costs now counts as a qualified distribution, putting the 529 ahead again.