Feedback occurs because the amplified sound from the hearing aid is picked up at the hearing aid microphone and allowed to pass through the hearing aid again. If the amplification is large enough, the signal passing through the feedback loop will become louder and louder, eventually resulting in the high-frequent whistling sound.
Fortunately, the feedback cancelling systems of modern top range hearing aids are very effective in minimizing the problem of feedback.