Game Freak logic, pal. Get used to it.
Nobody really knows, except maybe Game Freak. But, if we take a shamble down the Logical Path, we may find an answer.
What we know about the Porygon line
1) They are artificiallly made
2) They live in cyberspace
3) In order to evolve, they require various computer parts.
The conclusion we can draw from this is that Porygon, Porygon2 and Porygon-Z are essentially computers, a highly-advanced AI system that lives inside your WiFi. O.o
Additional software was installed to make it a better Pokémon. It began acting oddly, however.
This entry, found in the Diamond/Pearl Pokédex, says that people are able to add more and more sophisticated technology to Porygon. Porygon-Z was the result of adding additional, state-of-the-art AI to Porygon2. As plainly seen in films such as WALL-E and I, Robot, the more sophisticated artificial intelligence gets, the chances increase of it defeloping a mind of it's own. While both Porygon and Porygon2 were extremely advanced artificial intelligence units, they were still under human controll. Porygon-Z appears to have broken that pattern.
Its programming was modified to enable it to travel through alien dimensions. Seems there might have been an error...
The Pokédex entry for Porygon-Z in Pokémon Y states that Porygon-Z experienced technical difficulties. But, when you add in the deductions from the Diamond/Pearl entry, we realize that perhaps these were not errors. Perhaps this was when the technology in the Porygon line became so sophisticated that Porygon-Z developed a mind of it's own? Porygon-Z did not want to obey humans, so it didn't. Humans, refusing to believe that something that they created was getting beyond their control, simply wrote it off as an error. They thought that it was, in the words of the great Vizzini, "inconceivable" that anything could defy them.
And so we come to the end of the Logical Path. By picking apart different Pokédex entries and using prior knowledeg of the subject, we came to a conclusion: The "error" experienced by Porygon-Z was it's forming of it's own thoughts, becoming almost sentient. I hope this answers your question!