Quantum subspace expansion algorithm for Green's functions