Let $A$ and $B$ be two positive semidefinite symmetric matrices such that for all $x$ in the range of $B$, $x^{\top}Ax \leq x^{\top}Bx$. I am wondering if the following holds true: for all $\lambda > 0$ and for all $x$ in the range of $B$ $$ x^{\top}(B + \lambda I_d)^{-1}x \leq x^{\top}(A + \lambda I_d)^{-1}x. $$ Where $I_d$ denotes the identity matrix. Note that I am not assuming $A$ or $B$ to be invertible which is why we add $\lambda I_d$.
If $B$ is full rank the result is easier to demonstrate as "for all $x$ in the range of $B$, $x^{\top}Ax \leq x^{\top}Bx$" is equivalent to $A \leq B$ (in the partial order on the set of positive semidefinite symmetric matrices), and then proving that $A+ \lambda I_d \leq B +\lambda I_d$ implies $(B +\lambda I_d)^{-1} \leq (A + \lambda I_d)^{-1}$ is not too difficult (for example https://mathoverflow.net/questions/297542/the-statement-that-a-ge-b-implies-a-1-le-b-1-is-still-true-for-matri). However the proof does not generalise to the inequality I am trying to prove as the ordering is only considered on a subspace (here the range of $B$).
Let $t,c>0$ and $C=B+tP+c(I-P)$ where $P=BB^+$ denotes the orthogonal projection onto $\operatorname{range}(B)$. For any fixed $t>0$, note that $A\le C$ when $c$ is sufficiently large. To see this, take any $u\in\operatorname{range}(B)$ and $v\in\operatorname{range}(B)^\perp=\ker(B)$. Then \begin{align*} (u+v)^T(C-A)(u+v) &=(u^TBu+tu^Tu-u^TAu) - 2u^TAv + (cv^Tv - v^TAv)\\ &\ge t\|u\|^2 -2\|A\|\|u\|\|v\| + (c-\|A\|)\|v\|^2, \end{align*} which is nonnegative when $\|A\|^2 < t (c-\|A\|)$.
It follows that $P(B+tP+\lambda I)^{-1}P=P(C + \lambda I)^{-1}P\le P(A + \lambda I)^{-1}P$. Therefore $$ x^T(B+tP+\lambda I)^{-1}x\leq x^T(A + \lambda I)^{-1}x $$ for all $x\in\operatorname{range}(B)=\operatorname{range}(P)$. Let $t\to0^+$, the result follows.
Alternatively, by a change of orthonormal basis, you may assume that $B$ is a block-diagonal matrix in the form of $B_1\oplus0$, where $B_1>0$. If we partition $A$ as $\pmatrix{A_1&A_2\\ A_2^T&A_3}$ in a conforming manner, then the given condition means that $0\le A_1\le B_1$. Using Schur complement, we see that the first diagonal sub-block of $(A+\lambda I)^{-1}$ is $$ \left[(A_1+\lambda I)-A_2(A_3+\lambda I)^{-1}A_2^T\right]^{-1} \ge(A_1+\lambda I)^{-1} \ge(B_1+\lambda I)^{-1}. $$ Hence the result follows.