That is a very deep question, and one that the Artificial Intelligence community would love to have a definite answer to.
The basic process is simple enough in a sense, you study something for a long time, look closely at something that interests you, examine the thing itself, and what other people have done in the process of investigating it; then you go do something else, and wait for a good idea.
The interesting bit seems to be the ways in which “good ideas” occur; and the almost as complex bit is how we make our initial decisions about what is “good” and what isn’t; and what is worth putting in further time and effort to investigate.
The mechanisms by which we get new ideas seem to be deeply complex.
Some of them are built into the mechanisms of our brains, and have been selected over deep time by the process of differential survival of variants (those that were a little better giving the individuals a slightly better chance of surviving).
Some we learn from culture, where ways of thinking about things that worked for others in the past have been handed down.
Some we discover for ourselves (via a variety of mechanisms, though in most people this is rare).
David Snowden has some great insights about information flows and decision making in complex adaptive systems (his you tube videos are worth watching) that are relevant in this context.
It is a subject that one can spend a very long time studying and experimenting with (I have since the mid 60s, and the more I learn the more complex and interesting the picture becomes).