Short answer
The optimal user experience would be to log them into their account.
Long answer
However, one could put an argument forth that if the user realises they just tried logging in via the wrong screen, they would instead expect to be presented with an error message as per your first point. The reason for this is that most sites use this approach and, because of this, there is a familiarity with this approach.
Why does familiarity matter? Because familiarity breeds expectation, and this usually leads to a better user experience because it matches what users are expecting. Here is some further reading to back this assertion up:
I would argue that you don't want to step away from a familiar approach unless you have something that is significantly better and therefore warrants the change.
So, would logging the user in regardless of the screen they were on warrant such a change? I believe it does because the change from the norm is not too drastic and it most certainly improves the user experience.
Finally, as an aside, you may also find the following article interesting:
https://articles.uie.com/user_expectations/