What is causing my middle toe to be sore off and on, at the farther joint, for months?

Claw toe. Changes are the toe is trying to turn downward forcing the joint to hit the top of the shoe.
Possibly gout. Gout usually presents with swelling of the great toe, but it can occur in other joints as well, like the knee. It is really painful, and has swelling, and can have fever. This comes at times and can last days to weeks. A visit to the doctor is a good first step to rule out gout.