When does the generalized Cantor space embed in a $\kappa$-compact space
Let $\kappa$ be an uncountable regular cardinal that is not weakly compact and let $C$ be a $\kappa$-compact subset of ${}^\kappa 2$. Assume, towards a contradiction, that there is a continuous injection of ${}^\kappa 2$ into $C$. Since $C$ is closed in ${}^\kappa\kappa$, Lemma 2.9 of this paper shows that $C$ contains a closed set homeomorphic to ${}^\kappa 2$. By our assumption, $\kappa$ is not weakly compact and a theorem of Hung and Negrepontis (see Corollary 2.3 of the above paper) implies that the spaces ${}^\kappa 2$ and ${}^\kappa\kappa$ are homeomorphic. This is a contradiction, because an easy argument shows that $\kappa$-compact subsets of ${}^\kappa\kappa$ do not contain closed subsets homeomorphic to ${}^\kappa\kappa$ (see Fact 1.5 of the above paper).
Let $\kappa$ be indestructible supercompact, let $\lambda>\kappa$ be inaccessible and let $G$ be $Col(\kappa,{<}\lambda)$-generic over $V$. In this situation, standard arguments (see, for example, Lemma 7.6 of this paper) show that, in $V[G]$, all subtrees of ${}^{{<}\kappa}\kappa$ with more than $\kappa$-many $\kappa$-branches contain a subtree isomorphic to ${}^{{<}\kappa}2$. In particular, in $V[G]$, $\kappa$ is weakly compact and every $\kappa$-compact subset of ${}^\kappa 2$ of cardinality greater than $\kappa$ contains a continuous injective image of ${}^\kappa 2$.
Let $\kappa$ be a weakly compact cardinal with the property that there is a subset $A\subseteq\kappa$ such that $\kappa^+=(\kappa^+)^{L[A]}$ and the set $\{\alpha\in S^\kappa_\omega \mid cof^{L[A\cap\alpha]}(\alpha)=\omega\}$ is stationary in $\kappa$. In this situation, a modification of a classical argument of Solovay shows that there is a weak $\kappa$-Kurepa tree, i.e. a subtree $T$ of ${}^{{<}\kappa}2$ with $\kappa^+$-many $\kappa$-branches and $\vert T(\alpha)\vert=\vert\alpha\vert$ for stationary many $\alpha<\kappa$. Since $\kappa$ is weakly compact, the tree $T$ contains no $\kappa$-Aronszajn subtrees and a theorem of Juhász and Weiss (see Lemma 2.2 of the first paper) shows that the corresponding closed subset $[T]$ of ${}^\kappa 2$ is $\kappa$-compact. By results of Mekler and Väänänen, there is no continuous embedding of ${}^\kappa 2$ into $[T]$.
The existence of weak $\kappa$-Kurepa trees at every inaccessible cardinal $\kappa$ is consistent with the existence of very large large cardinals (including supercompact cardinals). This is discussed on page 33 of this paper by S. Friedman, Hyttinen and Kulikov.
EDIT:
As Boaz has pointed out in the comments, there is a mistake in my alleged proof. After thinking about it a bit, I believe it is a genuine mistake (i.e., not quickly fixable). This error does not come in until the end of my argument (Lemma 5), so I will leave the original post up and intact in case the first part of the argument (Lemmas 1-4) can still be useful.
ORIGINAL POST:
Every weakly compact cardinal has this property.
I don't know a reference for this, but I can give a proof. The proof is just a generalization of one proof for this fact when $\kappa = \omega$.
Proposition: If $\kappa$ is weakly compact, then the generalized Cantor space $2^\kappa$ is homeomorphic to a subspace of every $\kappa$-compact subset $C$ of $2^\kappa$ with $|C| > \kappa$.
Proof: I'll try to break it up into bite-sized lemmas:
Lemma 1: Suppose $X$ is a Hausdorff space in which an intersection of fewer than $\kappa$ open sets is open. Then every $\kappa$-compact subspace of $X$ is closed. Furthermore, if $X$ is $\kappa$-compact then a subspace $C$ of $X$ is $\kappa$-compact if and only if it is closed.
Proof: (In many ways, this is just like the proof for $\kappa = \omega$.) Suppose $A \subseteq X$ is $\kappa$-compact, and fix $x \notin A$. For each $y \in A$, let $U_y$ and $V_y$ be open sets with $x \in U_y$, $y \in V_y$, and $U_y \cap V_y = \emptyset$. The collection $\{V_y : y \in A\}$ covers $A$, so by $\kappa$-compactness some subset $\mathcal{V}$ with $|\mathcal{V}|< \kappa$ still covers $A$. By our assumptions about $X$, $$\{U_y : V_y \in \mathcal{V}\}$$ is a neighborhood of $x$, and it must be disjoint from $A$. Thus $A$ is closed.
It remains to show that if $X$ is $\kappa$-compact, then every closed $C \subseteq X$ is also. If $\mathcal U$ is an open cover of $C$, then $\mathcal U \cup \{X - C\}$ is an open cover of $X$. Since $X$ is $\kappa$-compact, we may pass to a $<\kappa$-sized subcover. Removing $X-C$ from this subcover if necessary, we obtain a $<\kappa$-sized subset of $\mathcal U$ that covers $C$. $\ $QED
Lemma 2: Assume $\kappa$ is regular. In the generalized Cantor space $2^\kappa$, any intersection of fewer than $\kappa$ open sets is open.
Proof: Using regularity, it is easy to see that this is true for basic open sets. The result follows easily. $\ $QED
Putting these two lemmas together with Joseph van Name's answer to your previous question, we obtain:
Lemma 3: If $\kappa$ is weakly compact, then $C \subseteq 2^\kappa$ is $\kappa$-compact if and only if it is closed.
Lemma 4: If $\kappa$ is regular and $2^{<\kappa} = \kappa$, then every closed $C \subseteq 2^\kappa$ with $|C| > \kappa$ contains a closed subspace with no isolated points.
Proof: Fix a closed subset $C$ of $2^\kappa$.
By transfinite recursion, define a sequence of subsets of $2^\kappa$ as follows: $$C_0 = C$$ $$C_{\alpha+1} = C_\alpha'$$ $$C_{\lambda} = \bigcap_{\alpha < \lambda}C_\alpha \qquad \text{ for limit }\lambda$$ (here $C_\alpha'$ denotes the derived set, or Cantor-Bendixson derivative, of $C_\alpha$). Eventually this sequence stabilizes, and we obtain some $C_\rho \subseteq C$ with $C_\rho = C_\rho'$. Using the fact that $2^\kappa$ has a basis of size $\kappa$ (because $2^{<\kappa} = \kappa$), it is not difficult to show that $\rho < \kappa^+$ and that $|C_{\alpha+1} - C_\alpha| \leq \kappa$ for all $\alpha < \rho$. Because $|C| > \kappa$, it follows that $C_\rho \neq \emptyset$. Furthermore, since $C_\rho = C_\rho'$, $C_\rho$ has no isolated points. $\ $QED
Lemma 5: Suppose $\kappa$ is regular. Then $2^\kappa$ is the only non-empty, $\kappa$-compact, zero-dimensional Hausdorff space with a basis of size $\kappa$, no isolated points, and in which every intersection of fewer than $\kappa$ open sets is open.
Proof sketch: Let $X$ be any space fitting the above description. Let $\{B_\alpha : \alpha < \kappa\}$ be a basis for $X$ consisting of clopen sets.
We now define a map $\varphi$ from the tree $2^{<\kappa}$ into the set of clopen subsets of $X$. Begin by putting $\varphi(\emptyset) = X$. If $\alpha$ is a limit ordinal and $\varphi$ is already defined on $2^{<\alpha}$, then extend the map to $2^\alpha$ by taking intersections: $$\varphi(f) = \bigcap_{\beta < \alpha}\varphi(f|_\beta) \qquad \text{ for }f \in 2^\alpha.$$ If our map is already defined on $2^\alpha$, then define it on $2^{\alpha+1}$ by splitting each $\varphi(f)$, $f \in 2^\alpha$, into two clopen pieces. Do this in such a way that each piece is nonempty (recall there are no isolated points in $X$). Also, if $\emptyset \neq B_\alpha \cap \varphi(f) \neq \varphi(f)$, then split $\varphi(f)$ into $B_\alpha \cap \varphi(f)$ and its complement.
This tree defines a homeomorphism from $2^\kappa$ to $X$. If $f \in 2^\kappa$, our homeomorphism takes $f$ to the unique element of $\bigcap_{\alpha < \kappa}\varphi(f|_\alpha)$. This intersection is nonempty by $\kappa$-compactness, and it is a singleton by our use of the $B_\alpha$ in the successor stages of our construction. Thus the map is well-defined, and it's not too hard to check that it is a homeomorphism. $\ $QED
I admit I left out some details from this last proof. Please feel free to ask for more details if you want them.
Putting everything together, this finishes the proof of the proposition. $\ $QED
It is possible that $\kappa$ is weakly compact (and even more) but there is a $\kappa$-compact space $C\subseteq 2^\kappa$ such that $|C| = \kappa^{+} < 2^\kappa$.
First, let us note that if $\kappa$ is weakly compact then for every tree $T\subseteq 2^{<\kappa}$, the set of branches $[T]$ is a $\kappa$-compact subspace of $2^{\kappa}$. (Proof: let $\langle \sigma_\alpha \mid \alpha < \kappa\rangle$ be sequence of elements in $2^{<\kappa}$ such that $\{[\sigma_\alpha] \mid \alpha < \kappa\}$ is an open cover of $[T]$. Assume that for every $\alpha < \kappa$ there is $b\in [T]$ such that $b\notin \bigcup_{\beta < \alpha} [\sigma_\beta]$. Then, there is also $t\in T$ with the same property. Let $j\colon \langle V_\kappa, \in, T\rangle\to \langle M, \in \tilde{T}\rangle$ be a weakly compact embedding. By elementarity, there is $t\in \tilde{T}$ such that $t\notin \bigcup_{\alpha < \kappa} [\sigma_\alpha]$, but for all $\alpha < \kappa$, the length of $\sigma_\alpha$ is less than $\kappa$ so we may take $t\in \tilde{T}_\kappa \subseteq [T]$ - a contradiction).
It is consistent that $|[T]| = \kappa^{+} < 2^\kappa$ for a $T\subseteq 2^{<\kappa}$, $\kappa$ weakly compact. For example, let $T$ be the full binary $\kappa$-tree in $L$, and assume that $\kappa^{+} = (\kappa^{+})^L$ but $2^\kappa > \kappa^{+}$. By weakly compactness, every branch of $T$ belongs to $L$. In fact, similar arguments seems to show that if $\kappa$ is weakly compact and there is no tree with exactly $\kappa^{+}$ many branches then there is an inner model with a Woodin cardinal.