The lack of harm does not mean that the thought is being punished.
Generally speaking, you're right - it doesn't. However, in this particular case, I contest that it does: Laws are (or should be) put in place to prevent actual or potential harm to the public (inluding property), enforce the authority and continuity of the state and safeguard socially-ingrained customs and values.
When a law is passed that doesn't contribute towards any of those objectives, the natural question to ask is "why does this law exist?". Regarding the law in question, the only plausible answer can be "because the law-makers want people to stop fantasising about deviant sex as they consider this the first step on the road to rape and murder". In other words , they try to stop people from thinking about it because -according to the lawmakers' reasoning- if they
think about it they will go and
do it.
The only reason the law doesn't say "don't
think about it" is because that would be an un-enforceable law, as the technology to monitor people's thoughts doesn't exist yet. So the next best thing is to find evidence of people's thoughts (i.e. viewed images) and hence indirectly punish people for these thoughts.
"We must respect the law, not let it blind us away from the basic principles of fairness, justice and freedom"