This may vary by country, but generally you can keep them on, but you might want to turn the volume down just before you go through the scanner to avoid any disturbing noise coming from the interference with the signal from the scanner itself .
TSA in the US released a statement that it is safe to keep them on through the X-ray process:
hearing devices such as hearing aids, cochlear implants, external
component of cochlear implants, and middle ear implants are not
affected by X-ray inspection or walk-through metal detector screening
Source
If you are still worried simply ask an agent working there, they will advise you if you do need to take them off. For more information about flying with hearing aids this blog seems to be a good source.