An attorney-client relationship generally doesn't form until the lawyer and client agree to it. But the attorney-client privilege protects some communications made before the prospective client hires the attorney, and even some where there's never any hire.
(For all kinds of information about lawyer-client relationships, including confidentiality exceptions, see The Attorney-Client Privilege.)
Each day, countless people with legal problems consult attorneys before deciding if they want to hire them. Many, if not most, criminal defense attorneys offer free consultations for potential clients. Understandably, some defendants wonder whether such consultations—with attorneys who don't yet and might not ever represent them—are protected.
In general, as long as the prospective client is seeking legal advice or representation and reasonably believes the communication will be confidential, the consultation is privileged. This is so even if the would-be client never pays or hires the attorney. (But if the attorney declines to represent a potential client who nevertheless continues to communicate with the attorney, the result is different.)
The potential-client-confidentiality principle also comes into play when an arrestee consults with a public defender at or from the police station or jail. The conversation is privileged, even though the public defender does not, and may never, represent the arrestee, and even though the public defender doesn't receive a fee. (But see Can a jail record my telephone conversation with my lawyer?)
Though the law is mostly settled in this area, there are nuances and potential differences from state to state. So, it's a good idea to start any communication with an attorney who doesn't represent you by confirming with him or her that your communications will be privileged.