Scientists advising the government told them that, with appropriate measures (such as soap everywhere, >1m distance between everyone, etc.), it was no more dangerous than going to buy some food, which is still authorized. The full scientific advice has not been published yet (it should be though), but here is the head of the scientific committee confirming it :
Le conseil scientifique a considéré qu’il n’y avait pas d’élément
pour penser qu’il y aurait un surrisque pour ces personnes à condition
que les élections soient organisées de façon pratique
The scientific committee considered there was no element indicating
more risk [to go vote than to go shopping] for those people [elderly
people], if the elections are organized in a practical way.
There is also a question of politics and timing : on Thursday morning all parties asked that it be maintained (in particular the right-wing Senate president, who is now blamed for it), so they had to decide that.
However, later the same day, the confinement measures were decided, which seemed to contradict the possibility to vote. But politically it was too late, cancelling the elections would go against advice given by all parties on Thursday morning.
Since Macron was expected to lose the elections (which he mostly did), cancelling the election after every other party expressed against it would have been seen as an antidemocratic political maneuver.
Some of the opposition parties have since then declared that they only accepted to maintain the elections before the confinement measures were decided, and thus that they could not decide in all knowledge, and would have changed their minds after the confinement measures were announced.