While you may want to call the plan administrator to confirm, there should be no penalty associated with the withdrawals used for tuition, housing, etc associated with state A university. Each year you are considered a resident of state A, you can deduct some portion of contributions from State A taxes. When you move and are no longer a State A resident, you would no longer take the deduction. This is a separate issue from withdrawals for college expenses.
Of note, generally when you do your taxes if you drew money out of the 529 for college expenses, you will receive a 1099-Q. Hold on to this document AND receipts that match the amount (tuition, books, laptop, housing, meals required to be purchased if living on campus). The IRS will likely send a letter after you file taxes, asking for those receipts. You dont provide the proof with your taxes, only when asked by IRS.
My experience is working for a broker on the 529 plans team a few years ago.