I am not sure, but I think miners are free to place transactions in the block in any order they want.
The only stipulation is that parent transactions come before child transactions. Usually this rule is irrelevant, because the vast majority of transactions have their parent transactions already confirmed in previous blocks. The time this does apply is in the case of CPFP or any other situation where a transaction spending an unconfirmed output confirms in the same block as its parent. In these cases, the parent(s) must be earlier in the block than the child(ren).
Having said that, although miners are otherwise free to order transactions any way they like, transactions are generally ordered in terms of fee rate, from highest to lowest, as the software building the candidate block simply picks transactions by their fee rate, from highest to lowest.