The short answer is that voting is simply a more complicated process. Not only are there considerably more security concerns, there is plenty of room for human error both on the side of those administering the voting but also from the voters themselves.
Ballots are cast by individuals who may or may not have registered correctly beforehand, and may or may not cast their ballot correctly. The people administrating the voting process can also make mistakes as they have to process thousands of ballots. This isn't a simple matter of counting them either and submitting a number via the honors system, there are checks and security concerns at each step as ballots have to be secure from tampering by any of the thousands of election workers involved. If there are inconsistencies, it's a major headache to go back and correct them, and poll workers often work very long hours. That's not even to mention the complications that things like affidavit voting bring in to play, and the fact that many counties are underfunded and understaffed for voting days. Some state's problems are idiosyncratic due to how their constitutions handle voting, and some don't have many problems at all. It's very difficult to generalize without simply pointing out that states face many unique challenges.
Consider also that voting is not done anonymously, and even when someone is registered incorrectly, they can often vote by affidavit ballots or other means if they so choose. These are often maintained separately from other votes. The standards for security and validation are far, far higher for voting.
For the most part, states do get the outcomes correct. Votes also happen more often than every two years. Elections are being held constantly, and federal-level politics is only one part of the broader election process.
To put simply, lotteries are very simple by comparison. There is no need to verify each purchaser, just winners. There is no need to verify the validity of a win outside of having the physical lottery ticket, which requires no extra administration. Even if a mistake does happen, it is relatively trivial to change after the fact.