Would it be legal to put a tax on a non tax resident, based on previous residence?
Yes. The UK already has the Statutory Residency Test where you can still be considered tax resident if you have sufficient ties to the UK and are not living there any longer. The end goal is to capture those HMWI that have left the UK in last few years making escaping the tax impossible for them.....it's evil....lol.
Seems things move fast and this is far worse idea...enhancing exit taxation

Costly departures: Why an exit tax looks more likely than a wealth tax
https://www.msn.com/en-us/money/eco...oks-more-likely-than-a-wealth-tax/ar-AA1J2uP7