It is trivial to see that:
If $X$ is Hausdorff, then every compact subset of $X$ is closed.
I am asking under what condition does the converse hold, i.e. when does
If every compact subset of $X$ is closed, then $X$ is Hausdorff
hold.
EDIT:
Sorry for whoever just read the question, I corrected the title and the whole question. It should be clear now.
As for me, this questions sounds unnaturally, but seems to be not so trivial. It seems the following. Let $X$ be a space such that every compact subset of $X$ is closed. Then $X$ is $T_1$, because each one-point subset is compact.
Proposition 1. If $X^2$ is a sequential space, then $X$ is Hausdorff.
Proof. Suppose the opposite. Then the diagonal $\Delta=\{(x,x)\in X^2:x\in X\}$ is not closed in $X^2$. Since $X^2$ is a sequential space then there exists a sequence $\{(x_n,x_n)\}$ of points of $\Delta$, converging to a point $(x,y)\in X^2\backslash\Delta$. Without loss of generality we may suppose that $x_n\not=y$ for each $n$. The sequence $\{x_n\}$ converges to $x$. Therefore a set $X_0=\{x\}\cup\{x_n\}$ is compact. Hence $X\backslash X_0$ is an open neighborhood of $y$. Since the sequence $\{x_n\}$ converges to $y$, there exists a number $n$ such that $x_n\in X\backslash X_0,$ a contradiction. $\square$
Example 1. There exists a non-Hausdorff space $X$ such that each compact subset of $X$ is closed.
Put $X=\omega\cup\{\alpha\}\cup\{\alpha’\}$, where $\alpha\not=\alpha’$ and $\{\alpha, \alpha’\}\cap\omega=\varnothing$. Let $\mathcal F$ be a free ultrafilter on the set $\omega$. Define a topology $\tau$ on the $X$ as follows. A subset $U$ of $X$ belongs to $\tau$ iff $U\subset\omega$ or $U\cap\omega\in\mathcal F$. Since $\mathcal F$ is an ultrafilter, we can easily check that each compact subset of $X$ is finite and, hence, closed in $T_1$-space $X$.
The following questions are already answered by Martin.
For the sake of future advances in this direction I formulate the following questions.Exists a non-Hausdorff space $X$ such that each compact subset of $X$ is closed, provided:
$X$ is compact?
$X$ is locally compact?
$X$ is a "$k$-space"?
$X$ is a "$k_\omega$-space"?
$X$ is a Fréchet-Urysohn space?
$X$ is a sequential space?