Why do we require $K$ to be compact instead of just finite in $(X=\mathbb{R} \cup \{P\}, \tau_2=\tau_e \cup \{X\setminus K\})$ for compactness? Example 1:
Let $\tau_{disc}$ be the discrete topology
We know $(\mathbb{R},\tau_{disc})$ is not compact
If we add a point P so that  we have $X=\mathbb{R} \cup \{P\}$ and define a new topology as
$\tau_1=\tau_{disc} \cup \{X\setminus F\}$, where $F$ is $F\subseteq \mathbb{R}$ and  finite, then the new space $(\mathbb{R},\tau_1)$ is compact.
The reason is that if we take any open covering, there would be an open set containing P  which is almost everything but a  finite quantity $t$ of points, then we can take t open sets, one for each point, and we have a covering made of $t+1$ open sets
Example 2
Let  $\tau_{e}$ be the euclidean topology
We know $(\mathbb{R},\tau_e)$ is not compact
If we add a point $P$ so that  we have $X=\mathbb{R} \cup \{P\}$ and define a new topology as
$\tau_2=\tau_e \cup \{X\setminus K\}$, where $K$ is $K\subseteq \mathbb{R}$ and  compact, then the new space $(\mathbb{R},\tau_2)$ is compact.
Why isn't enough to apply the same reasoning as in Example 1 and define K as finite, instead of compact?
 A: It is certainly possible to give $\Bbb R\cup\{P\}$ the topology $$\tau_3=\tau_e\cup\{X\setminus F:F\text{ is a finite subset of }\Bbb R\}\;,$$ and the resulting space is indeed compact. It is not, however, Hausdorff: if $x\in\Bbb R$, there do not exist $U,V\in\tau_3$ such that $x\in U$, $P\in V$, and $U\cap V=\varnothing$. The space $\langle X,\tau_2\rangle$, on the other hand, is Hausdorff, and since it is compact and Hausdorff, it is even normal. (In fact it turns out to be homeomorphic to $S^1$, the unit circle, so it is even metrizable.) Thus, $\langle X,\tau_2\rangle$ is a much nicer space than $\langle X,\tau_3\rangle$. Thus, if we’re looking for a nice compact space that has $\Bbb R$ as a dense subspace, $\langle X,\tau_2\rangle\rangle$ is preferable to $\langle X,\tau_3\rangle$. (Some people even make Hausdorffness part of the definition of compactness, so for them the space $\langle X,\tau_3\rangle$ isn’t compact.)
In any case, these examples are almost certainly setting you up for the definition of the one-point (or Alexandroff) compactification. A compactification of a space $X$ is an embedding of $X$ into a compact Hausdorff space $Y$ as a dense subspace. Your examples embed $\langle\Bbb R,\tau_{\text{disc}}\rangle$ and $\langle\Bbb R,\tau_e\rangle$ as dense subsets of compact Hausdorff spaces, so they are example of compactifications. My example above is an embedding of $\langle\Bbb R,\tau_e\rangle$ into $\langle X,\tau_3\rangle$ as a dense subset, and $\langle X,\tau_3\rangle$ is compact, but it’s not Hausdorff, so this is not an example of a compactification of $\langle\Bbb R,\tau_e\rangle$.
Your examples are not just compactifications: they are compactifications in which only one point has been added to the original space, hence the name one-point compactification. It turns out that such a compactification of a space $\langle X,\tau\rangle$ exists if and only if $X$ is a locally compact Hausdorff space, and in that case the one-point compactification is defined exactly as in Example 2: the open nbhds of the new point $P$ are the sets of the form $\{P\}\cup(X\setminus K)$, where $K$ runs over all compact subsets of $X$.
A: The 2nd version is a general construction for any (Haussdorf) topological space $X$, and is called the 'one point compactification'.
If we have an open cover $U_i$ of $X\cup\{P\}$, then $P$ is also covered by some base set $U_i=(X\cup\{P\})\setminus K$, but then the rest must cover the compact $K$ and thus a finite subcover can be selected.
Observe that the 1st version is a special case of the above, as in a discrete topological space the singleton sets are all open, thus they form an open cover, so exactly the finite subsets  are the compact ones.
