This is less because of the order you collect them and more because keys take a couple seconds to register. You got to the end too quickly after getting the last key and it hadn't counted yet. It's not an issue with the other order because it takes longer after collecting the key to get to the exit, so that necessary time has already passed by the time you get there.