Is every compact set is closed in any topological space?

No. The simplest counterexample is arguably this. Consider $X = \{0, 1\}$ with the indiscrete topology i.e. the only two open sets are $\emptyset$ and $X = \{0, 1\}$ itself.

Then trivially any subset of $X$ is compact. After all, any open cover at most contains just those two open sets. But, for example, the singleton subset $\{0\}$ of $X$ is not closed because its complement $X \setminus \{0\} = \{1\}$ is not one of the two open sets listed above and therefore not open.


If the space is Hausdorff you can show any compact set is closed. In general it is not the case. For example, take any finite set with at least two points with the trivial topology then any singleton is compact but not closed.


A different kind of example: The co-finite topology on an infinite set $X.$ That is, any $A\subset X$ is open iff (i) $A=\emptyset$ or (ii) $X\setminus A$ is finite. Equivalently any $B\subset X$ is closed iff (i') $B=X$ or (ii') $B$ is finite. In this space every subset is compact.