Let $H$ be a $\mathbb R$-Hilbert space, $N:=\mathbb N\cap[0,\dim H]$, $A\in\mathfrak L(H)$ be compact and self-adjoint and $I:=\mathbb N\cap[0,\operatorname{rank}A]$. By the spectral theorem, $$A=\sum_{i\in I}\lambda_ie_i\otimes e_i\tag1$$ for some $(\lambda_i)_{i\in I}\subseteq\mathbb R\setminus\{0\}$ with $$\lambda_i\ge\lambda_{i+1}\;\;\;\text{for all }i\in I\tag2$$ and an orthonormal basis $(e_i)_{i\in I}$ of $\overline{\mathcal R(A)}$. Let $$\lambda_n:=0\;\;\;\text{for }n\in N\setminus I$$ and supplement $(e_i)_{i\in I}$ to an orthonormal basis $(e_n)_{n\in N}$ of $H$.
Let $k\in I$. Are we able to show that $$\sum_{i=1}^k\lambda_i=\sup_{\substack{B\le H\\\operatorname{dim}B=k}}\langle AB,B\rangle_{\operatorname{HS}(H)}\tag3,$$ where $B$ is identified with the orthogonal projection onto $B$ and $\operatorname{HS}(H)$ denotes the $\mathbb R$-Hilbert space of Hilbert-Schmidt operators?
"$\le$" is trivial: If $B:=\sum_{i=1}^ke_i\otimes e_i$, then $\operatorname{rank}B=k$ and $$\langle AB,B\rangle_{\operatorname{HS}(H)}=\sum_{n\in N}\langle ABe_n,Be_n\rangle_H=\sum_{i=1}^k\langle Ae_i,e_i\rangle_H=\sum_{i=1}^k\lambda_i.\tag4$$
For "$\ge$", let $B$ be a subspace of $H$ with $\operatorname{dim}B=k$ and $(x_1,\ldots,x_k)$ be an orthonormal basis of $B$. So, $$B=\sum_{i=1}^kx_i\otimes x_i\tag5.$$ How can we show that$\langle AB,B\rangle_{\operatorname{HS}(H)}\le\sum_{i=1}^k\lambda_i$?
$(1)$ reminds me strongly on the Courant-Rayleigh minimax principle. Moreover, we know that $A$ is trace-class if its singular values $(\sigma_i)_{i\in I}$ are summable and $A$ is Hilbert-Schmidt if $(\sigma_i^2)_{i\in I}$ is summable. This seems to be related as well.
Remark: Note that a finite rank operator $B$ trivially belongs to $\operatorname{HS}(H)$. Moreover, the composition of a bounded operator (such as $A$) with a Hilbert-Schmidt operator (such as $B$) belongs to $\operatorname{HS}(H)$ as well.
BTW, if $\operatorname{rank}A=\infty$ (hence $I=\mathbb N$, is it possible that $\overline{\mathcal R(A)}\ne H$ (hence $(e_i)_{i\in I}$ is not already an orthonormal basis of $H$)?
What you want to show is that if $P$ is a projection with $\operatorname{Tr}(P)=k$, then $$ \operatorname{Tr}(AP)\leq\sum_{j=1}^k\lambda_j. $$ You have, by $(1)$, that $A=\sum_j\lambda_jE_j$, where $E_1,E_2,\ldots$ are pairwise orthogonal rank-one projections. Then $$\tag1 \operatorname{Tr}(AP)=\sum_j\lambda_j\operatorname{Tr}(E_jP) $$ This equality is justified by the fact that $$\operatorname{Tr}(P\sum_{j>m}\lambda_jE_j)\leq\|\sum_{j>m}\lambda_jE_j\|\,\operatorname{Tr}(P)=|\lambda_{m+1}|\,k\to0.$$
Now the problem is reduced to show that if $\{\lambda_j\}\subset\mathbb R$ is non-increasing and $\{\beta_j\}\subset[0,1]$ with $\sum_j\beta_j=k$, then $$ \sum_j\lambda_j\beta_j\leq\sum_{j=1}^k\lambda_j. $$ This is a well-known inequality (I don't know a name for it; it appears naturally when doing majorization). We have (note that $\lambda_j-\lambda_k\geq0$ for $j=1,\ldots,k$ and $\lambda_j-\lambda_k\leq 0$ for $j>k$) \begin{align} \sum_j\lambda_j\beta_j&=k\lambda_k+\sum_j(\lambda_j-\lambda_k)\beta_j \leq k\lambda_k+\sum_{j=1}^k(\lambda_j-\lambda_k)\beta_j\\[0.3cm] &\leq k\lambda_k+\sum_{j=1}^k(\lambda_j-\lambda_k)=\sum_{j=1}^k\lambda_j. \end{align}