Secondary sorting always depends on the last sort of a different type that you did. If they sort differently on recent, name or some other sort, their order when CP sorted can change. This happens to me with 4 identical Tyranitars and 2 identical dragonites, one of which is lucky, all the time. Had to scroll further down to test with two members of different species with the same CP but when tested the same logic applies.
Level and date of powering up do not matter for sorting as far as I'm aware and I doubt Niantic even stores the date of maxing, seems kind of irrelevant to me.