Because he repented.
That's the same as saying by faith alone (as compared to the Law) because one cannot repent without faith.
That's absurd. Anyone can repent for any reason whatsoever, even an atheist. Repentance merely means change of mind (metanoia in Greek). Anyone can regret something and resolve never to do it again. No faith needed there.
Od focurse, in the case of king david faith was a the factor for his metanoia, but I am willing to bet there are people of faith who don't repent of everything, even though they have faith.