I had foot surgery not once, but twice, during my late 40s, and one of the surgeries was to correct a hammertoe, which is a toe turned sideways that rubs against a toe next to it causing pain when wearing shoes and walking. I had a wonderful podiatrist who performed surgery to turn the toe around correctly and anchor it. Sounds funny, but the surgery worked, and the pain stopped.
Also, one of my friends had surgery for a condition called (if I remember accurately) Morton's Neuroma. It had something to do with the nerves and metatarsals, making two toes next to each other hurt, especially when she walked. She had surgery for it, also successful.
Also, as I believe has already been mentioned, arthritis can affect the toe joints just as it does other joints in the body.
If your toes are hurting, I suggest you find the best podiatrist available in your area and make an appointment. When your feet hurt, the rest of your body seems to hurt in sympathy.