It was a secret ballot so they didn't know who had done it, but the incident was reported to the police. Presumably the politician admitted to it before they went and interrogated and fingerprinted everyone to find out who did it.
But this raises the important question whether in a functioning democracy it is ever okay for the police to investigate who marked a specific ballot. If they're allowed to fingerprint people to find out, then this sets a precedent that would allow an authoritarian government to prosecute people voting for the wrong candidates.
You could also argue that this is exactly what happened here; the politician is being persecuted for his (unlawful) political expression during a secret ballot. Unfortunately since he confessed, there is no opportunity to question the involvement of law enforcement as a matter of principle.