Usually the precise pattern we have been studying isn’t available because Black has resources on the back rank (here his queen) that prevent White from finishing with the simple Qe8. But White still mates in this position, and again the secret is to start at f7 rather than h7, taking advantage of the g5 knight’s ability to support attacks on both squares. 1. Qxf7+, Kh8; 2. Qh5+, Kg8—and now the position has been reset but with the f7 pawn off the board. That’s important, for it allows 3. Qh7+, Kf8; 4. Qh8+, Ke7; 5. Qxg7#. The mate of the king on e7 looks surprising, but White’s pawn and knight seal off all of the king’s flight squares on the sixth rank.
This mate, like any that depends on confining the king, is sensitive to changes that give the king more room. Thus if Black’s queen were on c8 rather than d8 the mating sequence no longer would work, because then after Qxg7+ Black has Kd8. The details of these conditions may seem numerous and perplexing, but in practice you simply visualize your queen’s pursuit of the king’s path to see whether you can nail it in something like the manner described above. A pawn on e5 tends to be very important, both to prevent the king from escaping to d6 and to prevent Black from moving a knight to f6 so that it can protect h7.