I am currently in this very situation. I have just acquired advisors, and so my next task is to find a problem, a topic. So I cannot speak from hindsight, I can only speak from what I have heard from others, and from what my advisors are doing with me. Keep that in mind as you read the following.
First, there is no one right way to find a topic. There is a wide variety of methods that people can and have used. Any of the approaches that might be mentioned in this thread could be mixed with other approaches. All that matters is the final result, right?
There are relatively few students who enter a PhD program with a problem already in mind. While it may seem this can save time, it probably has more costs or risks associated with it. You have to be willing to find an advisor (and a school) who is willing to work with you as you work on the problem, which cuts down on your choice of schools. And if there is only one such potential advisor at the school you get into, and that person is not available or if it somehow does not work out between the two of you, then you're stuck looking for another school or having to pick a different problem.
So it is much more common to find an advisor first, then find a problem. The advise from one of my mentors was to first find an advisor, one who already has successfully seen at least one student through to completion of their PhD within the last five years, and then "work on whatever they are working on", at least as long as the topic area does not turn your stomach too much.
Different advisors work differently as well. I have seen that some advisors have the point of view that it is somehow their job to see to it that the sudent finds a problem to work on. Some professors even keep a stash of problems that they think would be suitable for a student to work on, from which they will draw and give to their students as needed. (I met one professor who no longer takes students because his stash is now empty. A bit sad, I think.)
My impression is that most advisors rely more on the student to find a suitable problem, one that student finds interesting (since interest improves motivation which is more likely to lead to success). But again there are many different approaches. Some advisors will suggest things for the student to read, which may include current research, or surveys containing statements of open problems, or sometimes will give you the names of other mathematicians to talk to. I think most advisors will tend to suggest things from areas that they are familiar with. But I did talk to one professor who said that his strategy is to think of some topic that he (the advisor) does not know much about but would like to learn more about, than have the graduate student read up on this topic and report back him, so that he (the advisor) will learn something new as well. This is interesting, but I think the advisor should know something about the problem are the student is working on. Finally, some advisors are very long leash, hands-off. Their attitude is, "Go out and find something that interests you. Come back and talk to me when you have something."
Whatever style the advisor uses to "help" the student find candidate problems, the advisor has several more important roles. One is gauging whether a problem is do-able or not, that is, within reach of the student in the timeframe of a dissertation. He or she cannot ever know for sure, but he or she will probably have a much better idea that the student will. The flip side of the same coin is knowing whether the candidate problem is of sufficient merit to be worthy of a PhD degree. This is something they can definitely gauge. And there are ranges of handling this as well. Sometimes several smaller results might be strung together to make a dissertation. Another role is to be aware of where the current frontiers of research are within the field. Generally one looks to current frontiers because that is where there will be known open questions, and that is where work will more likely be rewarded (papers will be published, employers will be favorably impressed). Unfortunately, the most popular frontier is where there will be the most other people working, and possibly working on the same problem you are. So one of the advisors roles is to also have a fair idea of what has already been done in the field, and possibly who may already be working on a given problem. It's a bad thing to be putting the final touches on your dissertation only to find that someone else has already published the result.
Source material for problems can come from a variety of sources. Most research papers will pose one or more open questions, areas for further exploration. Reading the most recent research papers will more likely show problems that have not been solved yet. There are also survey articles that will list both what is known and what is not known in a given area. There are some textbooks and monographs that will include open problems at the end of each section, or sometimes in a separate chapter. Most research institutions hold weekly seminars and colloquia where the speakers will talk about current research topics and open problems. Attend!
There is also word of mouth. I have had several potential problems described to me by mathematicians other than my advisor, typically from institutions other than my own, sometimes fellow graduate students. This is why networking with other mathematicians is so important. That is what most mathematicians do AFTER they get their PhD. So you should start doing this even while still a graduate student. I have found that most experienced mathematicians are quite willing to talk to even new graduate students about things. Just introduce yourself and start engaging.
And lastly, there is the task of developing your curiosity, the art of asking good questions. You could come up with a topic or problem just by asking yourself some questions, "on your own". This is an important skill, and one that can be developed systematically. In one of my graduate classes, a good portion of the class time was devoted to having the students present research papers that they read. One of the assignments the professor gave to the rest of the students was to submit at least one follow-up question for every paper presented by others. It would not have to necessarily be a thesis-worthy problem, but just one to get in the habit of asking questions.
Well, I've run on longer than I had originally intended, but I hope this has been helpful.