This question already has an answer here:
Is it ok to put your own king in discovered check as you take the other king? (Does the taking of the other king even count as a move, or is the checkmate the last move?)
Edit: When thinking about it, this isn't possible, at least not involving a checkmate, because if taking the king would result in a discovered check, the piece that is suddenly checking your king could also be used to take the original checker.
Take the following example. Is the last move (pawn) legal?
[fen "8/5P2/6q1/8/8/Q7/8/5k1K w - - 0 1"] 1.Qh3 Qg2 f8
I know white is not checkmate here, because the white queen can capture the black queen. The question is: Can white be considered to be in check at all, since taking the white king would expose the black king to the white queen? So, can white choose to move their pawn instead of taking the black queen?
Edit 2: My question is a duplicate of this question: Can a piece pinned to my king put the opponent's king in check?