How are chess engines able to rank a Mate in X above a Mate in X+Y? According to an engine, a mate in X moves = +infinity, since it is a forced win for it.

Also according to an engine, a mate in X+Y moves = +infinity, since it's a forced win (just more moves, but an engine doesn't care about this).

Due to the pruning in the minimax algorithm, if the engine first examines the "mate in X+Y moves" branch, it will see it's a forced win and then prune all the other branches.

Due to this pruning, it wouldn't examine the mate in X moves branch.

However, engines like Stockfish always rank a mate in X moves above a mate in X+Y moves. I refuse to believe these engines always know intuitively which branch to look at first (if this was the case, then the engines would first look at the mate in X moves branch first, and then prune the rest, which would make sense).

Question: Given this, how do engines always rank a forced win/mate in X above a forced  win/mate in X+Y, if they sometimes look at the latter first?
Engines don't use "infinity", usually they provide the value of position in centi-pawns, a queen will cost about 1000 centi-pawns and the price of the king is something about 30000 centi-pawns. When you are close to the mate, you get the evaluation at around 30000 minus about 1 queen for every move to reach the mate, to make it reasonable to sacrifice the queen for delaying the mate.

"mate in 1" becomes 29000, "mate in 2" becomes 28000 an so on, so engine has quite clear picture which move to make.

And reaching "mate in 10" only makes the engine to prune all branches that evaluate in anything less valuable, so "mate in 8" still stays on the table.