in reply to sort behavior explanation required

Could anyone please explain me on what basis the sorting is happening in the following two cases

The documentation can explain it if you read it :)