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
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
...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 (
Kc2), enabling your rook to create counter-threats.