A lawyer isn't actually allowed (or at least they can refuse access) to assist you during the interrogation.
It's not even specific for foreigners, this happens semi-routinely to japanese nationals too. However some of the cases where they got a confession in this way don't go even to court (most of the cases don't actually, it's one of the reason, together with a biased system toward prosecution, that the conviction rate is strikingly high, as it's the only way to maintain the pretense of the system).
Most of the populace isn't aware of these problems, as these info, while accessible, aren't talked in media. This is slowly changing, as multiple cases of people unjustly convicted for crimes they never committed (even murder), were revisited and the sentence overturned (however after 10 or even 20 years), and some of these people that are still alive, are doing activism (and some organizations got created to push for revisions of many cases)