It is not the strongest of the species that survives, nor the most intelligent, but the one most responsive to change. (Charles Darwin)
Mathematical research is by its nature unpredictable – if we knew in advance what the answer would be and how to do it, it wouldn’t be research! You should therefore be prepared for research to lead you in unexpected directions, and it may end up that you may find a new problem or area of mathematics more interesting than the one you were initially working in. (See also “Don’t be afraid to learn things outside your field” and “Learn the power of other mathematician’s tools“.)
Thus, while it is certainly worthwhile to have long-term goals, they should not be set in stone, and should be updated when new developments occur. One corollary to this is that one should not base a career decision (such as what university to study at or work in) purely based on a single faculty member, since it may turn out that this faculty member may move, or that your interests change, while you are there. (See also “Don’t base career decisions on glamour or fame“.)
Another corollary is that it is generally not a good idea to announce that you are working on a well-known problem before you have a feasible plan for solving it, as this can make it harder to gracefully abandon the problem and refocus your attention in more productive directions in the event that the problem is more difficult than anticipated. (See also “Don’t prematurely obsess on a single big problem or big theory“.)
This is also important in grant proposals; saying things like “I would like to solve <Famous Problem X>” or “I want to develop or use <Famous Theory Y>” does not impress grant reviewers unless there is a coherent plan (e.g. some easier unsolved problems to use as milestones) as well as a proven track record of progress.