Is it advisable to have a master or PhD thesis topic in mind before entering graduate school?
There may be advisers, departments, universities, countries (academic cultures) or fields where you need to come up with your own idea. I would not think this is the norm, however. In many cases Phd positions are financed by project funding so that the project is largely defined. This does not mean that the entire PhD is staked out in advance but the direction is. When you start a PhD you need an adviser which would imply that the field and direction of research of that adviser will determine the direction of your research. In many academic systems you directly apply to a PhD project which is pre-defined. I could probably come up with more cases that point away from come up with your own thesis topic.

That said, however, it is not inconceivable that someone could enter a system with an own idea but since coming up with great ideas commonly involves having a deep understanding of a field, and that in itself being one of the goals of a PhD, it would be a very rare case.

So depending where you are or where you are heading in the academic world, you do not need to know the thesis topic in advance. You will be looking for topics that may interest you and once finding positions announced decide if they fit your interests. It is rare that you find exactly what you dream of so many go for positions that are "close enough". Another point here is that you would probably not select a topic only, you would also consider the academic milieu and if you think it would be good for you and your endeavour into research.