When to move/centralize king? [fen "8/3k1ppp/2p2n2/r2p4/p2Pp3/4P3/PP2BPPP/4K2R w - - 0 1 "]


At this position Stockfish has recommended Kd2, and noticing how the black bishops are off the board the king seems safer centralizing itself, but ultimately when do you decide to advance/center the king and especially over advancing pawns or getting major pieces in better positions?
The general rule of thumb is that: if the queens are off the board then it's generally safe to keep the kings central in order to use them as active pieces (specially in endgames) instead of tucking them away into a safe corner. 

But that's just a general rule, and like any other rule in chess it is to be taken with caution, because at the end of the day everything still depends on the precise context (i.e. concrete assessment of main lines). Easiest cases to assess are when there are not many open files and diagonals towards the king, because otherwise, well-coordinated minor pieces can tactically exploit an exposed king's position to either win material or win tempi. 

In your example, Kd2 is very natural because it successfully achieves two goals: it centralizes your king (so bringing it equally close to weak points such as b2 and f2) and it activates your rook. I emphasize successfully, because concretely speaking, there are currently no direct threats which prevent you from playing Kd2. If instead you castle (assuming it's legal in this position), sure the rook gets activated, but the semi-open b-file (e.g. ...Rb5 though currently prevented by the bishop on e2) will eventually bound your rook to the defense of the b2 pawn, potentially followed by a3, and that's a healthy initiative for black with a dangerously advanced a-pawn. But with the king on d2, your king starts covering your queenside (Kc3-Kb4, or Kc2), enabling your rook to create counter-threats.