The first machine that everybody acknowledges as a computer is the colossus: https://en.wikipedia.org/wiki/Colossus_computer, although there is a bit of debate as in the USA a similar machine was built, and some debate is there which one is older. Both machines had the same purpose... The Germans did encrypt their messages in order to make them unreadable for the enemy during WWII. Even though they were in German, there were still English and Americans who had understanding of the German language (for obvious reasons). These computers were used to automatically find the right encryption keys so they could decipher the message, as humans doing it would take more years than a human lifespan provides. They were built in the period 1942-1945. They were also the first programmable devices, although some women had to climb into them and place some tubes or set some switches in order to program them, in stead of typing code, like we do today. Although the Z2 is older, I think the key lies in being programmable and thus being Turing-complete in being recognized or not. I could not find much info about that about the Z2.
Indeed some people do claim that if the Pascaline was a computer the abacus could be seen as a computer as well, although the Pascaline could be used in a more automated manner than an abacus. The Pascaline and an abacus are at least both not programmable, that's for sure.