What can I do about a mentally ill neighbor who annoys and harasses me when I walk by?

Police. File a report with the police. The mentally ill are usually closely monitored, and the police will appreciate having the information. They depend on neighbors. Hopefully this will go to a mental health court, and you will be doing a favor to yourself, to the law, and to your unfortunate neighbor. I would not wish mental illness on anyone.