Why isn’t the original window order always preserved when you undo a Show Desktop?
The answer is “Because the alternative is worse.”
Guaranteeing that the window order is restored can result in Explorer hanging.
When the windows are restored when you undo a Show Desktop, Explorer goes through and asks each window that it had minimized to restore itself. If each window is quick to respond, then the windows are restored and the order is preserved.
However, if there is a window that is slow to respond (or even hung), then it loses its chance and Explorer moves on to the next window in the list. That way, a hung window doesn’t cause Explorer to hang, too. But it does mean that the windows restore out of order.