Earned income is required for Roth contributions. If he has at least $6k of earned income in 2021 and the same in 2022, then he can contribute to Roth IRAs for both years.
Any withdrawals from a 529 won't qualify as earned income for Roth contributions. But it can be a source of cash.
To get $12k in cash from the 529:
Withdraw: $12,500
Basis: $8,065 ($20k/$31k*$12.5k)
Earnings: $4,435 (withdrawal - basis, 12.5k - $8,065 = $4435)
Penalty: $443.50 (10% of earnings)
Actual cash from withdrawal: $12,056
Income tax will also be due. That $4,435 could be taxed with an additional 10%, 12%, 22%+ (or it could be 0% - all depends on income.)
State income tax (and penalty) could also be due.
529 funds can also be used to pay student loans, transferred to another person in the family, or used for K-12 expenses on future kids (less than 20 years from now.)