A confession is usually only valid if it is made and attested to by the confessor -and can still be recanted (with varying success) later. Even if you directly confess verbally to a police officer, and deny it later, it’s a ‘he said, she said’. The courts will likely believe the officer, but it may not carry full weight. That’s why they have you write it in your own words, with a line or two saying that you’re doing it freely, etc. and then sign it. Of course, your statement that the confession was freely made could also be coerced, so it’s not uncommon to use audio or, now, video recordings.
The courts can’t use the heresay testimony of an eavesdropping guard in real life.
a) it is a violation by the state (the guard is an agent of the state) of attorney client privilege
b) eavesdropping is illegal, and here the prisoner probably does have ‘a reasonable expectation of privacy’ aside from confidentiality
c) the guard would have no direct knowledge of the crime, only a report of hearsay
d) this doesn’t fall under the usual exceptions to the hearsay rule (e.g. an “excited utterance” or “admission against self interest”)
e) the guard wouldn’t have much credibility, given a and b, in a “he said, she said” scenario
Lawyers don’t go to extraordinary lengths to assure that they are not overheard in jailhouse interviews because they know they can get it thrown out as a violation of confidentiality. In the case you described, it’s not really a ‘confession’.
On the other hand, there have been quite a few cases where law enforcement has tapped the intercom handset that bridge the plexiglass in the visit room or otherwise monitored, deliberately or accidentally. Almost all cases were decided against the state
There were numerous widespread violations in LA county in the second half of the 90’s, together they added up to thousands of cases, but that includes abuses not covered by your example. Similar issues arose in e.g. several “NY mob” ('70/80s) and “drug kingpin” trials ('80s) when court ordered wiretaps overheard attorney client conversations) The issue wasn’t whether this was a usable confession - it absolutely was not. The issue was whether law enforcement could use information acquired from the privileged to acquire or develop leads, which they could then investigate, develop and substantiate by other means. Sometimes it was allowed (e.g. if the cops could show they would have found out anyway), but often it was ruled “fruit of the poisonous tree” - i.e. “You shouldn’t have heard that, so you can’t benefit from it to build your case - the root was tainted, so the fruit is tainted”. Courts have tended to defend the rights of the individual, and expect law enforcement to know the boundaries.
Besides which, MaryEFoo is right,