Marx was a self-hating Jew.
He was ethnically Jewish, but probably not raised in Judaism given that his father converted to Lutheranism. (His grandfather was rabbi of Trier.) He solidified his atheism during his college years, when he embraced Hegelian philosophy. So not regarding himself as a Jew in any sense, it was easy for him to fall into garbage like he was uttering here, believing that getting rid of all religion would “liberate” humanity.