Yes? And there are plenty of immoral laws. Morality and legality often intersects but neither implies the other.
FWIW, I consider compulsory voting an immoral law, even though I generally consider voting a moral obligation. A democratic government derives its legitimacy from the people, as opposed to god (theocracy) or heritage (heritable monarchy). Voting is the means by which the people reaffirm the legitimacy of the political system that is in charge. When the very same political system compels the people to vote, ie. give it legitimacy, the value of the act of voting is watered down.
Many people feel that compulsory voting is immoral.
However, insofar as the legitimacy of the system of government depends on the franchise, it follows that a more thorough exercise of the franchise increases the legitimacy of the outcome[1].
There are however perfectly practical reasons to have compulsory voting. The biggest is that it dampens oscillations and creates pressure on the whole political system to focus on the median voter.
If you gave me a dictatorial remit to reform the US electoral system, compulsory voting would be one of the policy options I would choose. The others would be instant runoff voting, possibly the abolishment of the electoral college, holding elections on a Saturday and creating an independent electoral commission.
[1] Sophistry, of course. You can counter-argue that only willing exercise of the franchise grants legitimacy. But of course, it is economically irrational for any voter to turn out; just as it is irrational to pay taxes voluntarily. For any such system to work, compulsion is a necessity. You cannot make it go away, only decide where it is most required.
FWIW, I consider compulsory voting an immoral law, even though I generally consider voting a moral obligation. A democratic government derives its legitimacy from the people, as opposed to god (theocracy) or heritage (heritable monarchy). Voting is the means by which the people reaffirm the legitimacy of the political system that is in charge. When the very same political system compels the people to vote, ie. give it legitimacy, the value of the act of voting is watered down.