You could, but, in the U.S., ex post facto law is unconstitutional. Lenders have correctly gauged the odds of this provision of the U.S. constitution changing to be near zero.
This would be an ex post facto change. The government wouldn't be retroactively making the lenders guilty, it'd be a change in regulations. If this change was unconstitutional then you'd have situations like a company with a contract to dump industrial waste into a river going "oh sorry, I made this contract based on the regulations back then, so it's unconstitutional for you to make me stop polluting"
If you had a contract that was contingent on your ability to dump your waste in the river, and then a law was passed forbidding the dumping of waste, you would of course have to stop polluting, but your contract would be null and void as well.
Non-bankruptable student loans aren't "regulations" they are specific contracts between students, lenders, and the US government.
https://www.usconstitution.net/xconst_A1Sec9.html