In some countries, cyclists are legally required to wear a helmet. I believe that the advantages of this rule outweigh the disadvantages, although the question is not clear-cut.
The main advantage is safety. A helmet reduces the risk of serious head injury in a fall or collision, and head injuries are the most common cause of death among cyclists. A law also protects children, who may not understand the danger and whose parents may not insist on a helmet unless it is required. In Australia, where helmets became compulsory in the early 1990s, studies recorded a notable fall in head injuries. A legal requirement also reduces the strain on hospitals and on the families of those injured, since preventing a single brain injury saves very large treatment and care costs.
However, there are drawbacks. Critics argue that compulsory helmets discourage people from cycling, particularly for short, spontaneous trips or in cities with bike-sharing schemes, where users rarely carry a helmet. Since cycling is healthy and pollution-free, any fall in its popularity could harm public health and the environment. Some people also believe that adults should be free to decide on their own safety, and that helmets give a false sense of security that encourages riskier behaviour. Enforcement can also be costly and may fall unfairly on young or poorer cyclists.
On balance, I think the safety benefit is more significant than these concerns. Governments can reduce the drawbacks by making helmets cheap, or even free for children, and by improving cycle lanes so that cyclists are less exposed to traffic.
In conclusion, requiring helmets prevents serious injuries, and although it may discourage some cyclists, I believe the advantages are greater.