united-states
A similar issue came up in my answer to Can a private person deceive a defendant to obtain evidence?. I don't think the question itself is a duplicate, so instead I'll just copy the relevant section from my answer with minor edits.
The short answer is yes, the privilege applies.
The case of US v. Tyler, 745 F. Supp. 423 (W.D. Mich. 1990) matches your hypothetical almost exactly. The defendant, James Tyler, shared a prison cell with Melvin Deutsch, who said that he was a lawyer, had what appeared to be a law school diploma on the wall of his cell, and was addressed as "counselor" by other inmates; but in fact was not a lawyer. Nevertheless, correspondence between Tyler and Deutsch regarding Tyler's legal issues was held to be privileged and inadmissible.
Tyler was held to have had a reasonable belief that Deutsch was a lawyer, despite that Deutsch had never been licensed to practice law in any jurisdiction, and that the law school diploma was (presumably) fake. Tyler evidently didn't check on either of those things, and the court did not seem to think that he reasonably should have.
Also, Tyler apparently did not know the seemingly obvious fact that a convicted felon cannot practice law, let alone while actually in prison. However, this was not felt by the court to be "ingenuous": "To expect a layperson to be familiar with the internal discipline procedures of the Bar is unreasonable."
There is also a discussion of such situations in the following article:
Grace M. Giesel, Upjohn Warnings, The Attorney-client Privilege, And Principles Of Lawyer Ethics: Achieving Harmony, 65 U. Miami L.
Rev. 109 (2015). Available at this link
See Section IV.D.2 on page 140:
In addition to applying the honest-and-reasonable-belief analysis in
the attorney-client privilege setting to the question of representational
relationship, courts have also applied the analysis when the person consulted is not, in fact, a lawyer. The courts addressing this issue have
stated that the privilege applies to a communication even if the person
consulted is not admitted to any bar and has enjoyed no legal training. If
the putative client honestly and reasonably believes that the person consulted is a lawyer, and if the other requirements of the privilege are
satisfied, the privilege applies even though the person consulted is, in
fact, not a lawyer.
See the article for additional citations.
The article also mentions that certain states make this principle explicit by statute. For instance, the Kentucky Rules of Evidence, Rule 503(a)(3):
"Lawyer" means a person authorized, or reasonably believed by the client to be authorized to engage in the practice of law in any state or nation.