user12876:  [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?

user-1: TL;DR There is no real guideline. When the kings come out is a matter of intuition, i.e. experience.

When you need to activate the king - and when it's premature - is a matter of "king feeling"
"King feeling" is a subtle sense of knowing when it is safe to bring your king out of it's protective shell. This is not a matter of calculation ... and it's not a matter of applying rules

In the following game, black plays unconventionally. Instead of closing the position with 1...e5, he centralises his king:
[FEN "3r3r/p2nkp2/1p2p3/3P2pp/4Bq2/5P1Q/PP3P1P/2R1R1K1 b - - 0 1"]
[White "Shirov"]
[Black "Karpov"]

  1. Ne5            dxe6          
  2. f5             Rc7+          
  3. Kd6            Rxa7          
  4. fxe4           e7            
  5. Nxf3+          Kf1           
  6. Rde8           Qd7+          
  7. Ke5             *

Source for quote and example game: The wisest things ever said about chess by GM Soltis

user3594: 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. 

12876: <pre><code> [fen "8/3k1ppp/2p2n2/r2p4/p2Pp3/4P3/PP2BPPP/4K2R w - - 0 1 "]
</code></pre>

<p>At this position Stockfish has recommended <code>Kd2</code>, 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?</p>
 -1: <p><strong>TL;DR</strong> There is no real guideline. When the kings come out is a matter of intuition, i.e. experience.</p>

<blockquote>
  <p><strong>When you need to activate the king - and when it's premature - is a matter of "king feeling"</strong></p>
  
  <p>"King feeling" is a subtle sense of knowing when it is safe to bring your king out of it's protective shell. This is not a matter of calculation ... and it's not a matter of applying rules</p>
</blockquote>

<p>In the following game, black plays unconventionally. Instead of closing the position with 1...e5, he centralises his king:</p>

<pre><code>[FEN "3r3r/p2nkp2/1p2p3/3P2pp/4Bq2/5P1Q/PP3P1P/2R1R1K1 b - - 0 1"]
[White "Shirov"]
[Black "Karpov"]

  1. Ne5            dxe6          
  2. f5             Rc7+          
  3. Kd6            Rxa7          
  4. fxe4           e7            
  5. Nxf3+          Kf1           
  6. Rde8           Qd7+          
  7. Ke5             *
</code></pre>

<p>Source for quote and example game: <em>The wisest things ever said about chess</em> by GM Soltis</p>
 3594: <p><strong>The general rule of thumb is that</strong>: 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. </p>

<p>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. </p>

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