If you'll be applying to neurosurgery residency at age > 40, you will likely get some some rejections just because of your age, ilegal or otherwise. I am certain age was a factor when I applied (I was 35 at the time). This shouldn't disuade you if you're certain this is what you want to do. Be sure at your age you really have a good idea of what you're getting yourself into. Your best bet while in medical school will be to cozy up to your neurosurgery department at the medical school and convince them that although your 40+ years old you can still work like a 20-year old and your maturity will be an asset to the department. It will be much harder to convince people of this at a short interview.