Hanging a queen is something that can happen with a legal move.
Leaving a king in check (or moving a king into check, or moving away a piece that is blocking check) is a disallowed illegal move and needs to be undone. Moving Pg2-g5 orNg1-e3 or Bc1-g4 or Rh4-b5 are also illegal moves and need to be undone (even if you are able to capture the Knight on e3 or the Bishop on g4 or the Rook on b5 or the Pawn on g5 you are not allowed to do so because the move was impossible to legally make). In FIDE two illegal moves lose the game.
Asking why the King cannot be captured is similar to asking why bishops have to move diagonally, why rooks have to move orthogonally, why knights have to move in an L shape and are allowed to jump over pieces, why a pawn can move one or two squares on the first move and only one thereafter.
Pretty much every endeavor has basic rules. One example is the arithmetic proof below that only fails because of violating a basic rule:
Let a=b
Multiplying both sides by a gives a*a = a*b
subtracting b*b from both sides gives a*a - b*b = a*b - b*b
factoring both sides gives (a+b) * (a-b) = b * (a-b)
removing the common factor gives a+b = b
substituting b for a (because there were initially set to be equal) gives b+b=b or 2*b=1*b
removing the common factor gives 2=1
basic underlying rules are critical to avoiding ridiculous results.
I should have just said hanging a queen is a legal move
Moving your king into check is not could have made things less complicated
If you don't move your king out of check or move you king into check, who is breaking the rule?
Boxing and MMA rule:
"You protect yourself . . . at all times."
Chess is a mind game mma even if there is phycology behind it is a fighting game...