Julia Shaw in Scientific American:
There are three main reasons why people confess to crimes they did not commit.
The first is that they are voluntarily giving a false confession. Sometimes people confess to crimes because they want notoriety or they want to cover for someone else. For example, a gang member may confess to a crime committed by a higher-ranking gangster. They may also lie by admitting to a lesser crime than the one they are being charged with. Confess to a robbery and avoid a murder charge, for example. It’s a sneaky but effective way of creating an alibi.
The second is that they are being compliant. They are going along with the situation and are giving the interrogator what they think he or she wants to hear. They are guessing, like Brendan claims he did. Since police are keen on closing cases, they generally want to hear a confession. The thing with compliant confessions is that the person might say they committed a crime but might not actually believe it. Why might someone be compliant? They might be overwhelmed by the situation and want to escape it as soon as possible. One easy way to escape a hard line of questioning is to confess.
Third, they may have difficulty separating fact from fiction. This means that people can come to actually believe they committed a crime they did not commit, and they might even say they remember it happening.
More here.