Your king is the one piece you cannot afford to lose, and in the opening and middlegame it is also the most vulnerable. It is safe behind a wall of pawns with a few pieces nearby. Every move that weakens that wall or sends those pieces away gives your opponent a target, even if nothing happens on the next move.
The most common lapse is a pawn move in front of the castled king. Pushing the f, g or h pawn opens diagonals and files toward the king and creates holes that enemy pieces can use. Sometimes a pawn move is right, such as a luft against a back-rank mate, but each one should be a decision, not a habit. The Fool’s Mate below is the extreme case: two pawn moves open the e1–h4 diagonal, and the game is over.
The second lapse is leaving the king in the centre. Until you castle, the f2 or f7 pawn is defended only by the king, and once the centre opens the king can be checked from several directions. Many opening disasters, including the Fried Liver Attack, come from a king that stayed at home a move or two too long.
The third lapse is moving the defenders away. A knight on f3 or f6 is the best defender of a castled king: it guards h2 or h7 and keeps the enemy queen out. When that knight leaves, or is exchanged, attacks like Ng5 and Qh5 suddenly work. The same goes for the bishop that covers the light or dark squares around the king.
A good way to judge king safety is to count. How many enemy pieces are aimed at your king, and how many of yours defend it? If the attackers start to outnumber the defenders, it is time to bring a piece back, trade off an attacker, or close a line, before the attack starts. Waiting until the checks begin is usually too late.
Watch also for open lines. A half-open file in front of your king, or a long diagonal pointing at it, is an invitation for enemy rooks, queens and bishops. Before you open a line with a pawn trade, ask whose king it will help to attack.
ChessTensai flags a king-safety lapse when your move loosened the cover around your king or let in checks that the engine could use. If this category is high for you, back-rank and mating puzzles help, and so does the simple habit of castling early and moving king-side pawns only for a reason.