They can do it but not instantly. This is similar to any other account, if you close your checking account but someone cashes one of your checks you're on the hook, if you return your rental car but there's highway fees they'll charge you, if you order food from Seamless but requested extra guacamole in a comment they'll add it to the initial bill, ...
Likewise here if your EC2 takes a little while to stop, or if S3 is a little behind in adding up your bandwidth usage, or if the billing for any other of the myriad of AWS products is not quite real-time, I don't see why that would be illegal. Expecting that an accurate statement can be presented within a few seconds of clicking "close account" and guaranteed to be exact just because they are "online services" is a little peculiar.