Finding out who stated and proved some theorem first can require a more serious research than reading history of mathematics books and textbooks. Many examples can be given.
I give only a couple.
Casorati-Weierstrass theorem. It was mostly credited to Weierstrass (1876). Then papers of Casorati (1868) and Sokhotski were found (both of 1868). So the theorem obtained 3 names attached to it. And finally a more thorough research showed that it was stated in the book of Briot and Bouquet (1859).
Circle packing theorem of Andreev (1970). It was relatively little known outside the narrow circle of specialists, until Thurston made it popular in (1985) by proposing new point of view and several applications. This rasied the interest to the theorem, and soon people found that it was in fact proved by Koebe in 1936.
P. Koebe, Kontaktprobleme der konformen Abbildung, Berichte uber die Verhandlungen
der Sachsischen Akademie der Wissenschaften, Leipzig, Mathematische-Physische Klasse 88, 1936,
141-164.
Certainly no textbook and no history book contained this theorem until 1985.
Most mathematicians are not really interested in history, and for them the names of theorems are only convenient labels. Mathematical subjects go in and out of fashion. Once something becomes fashionable, someone digs the history, and finds who stated or proved some important theorem first. This does not necessarily lead to the change of the label.
See also https://mathoverflow.net/questions/285627 on the naming patterns of mathematical objects.
To address directly your question "how to find", let me give an example from my own career. In 1970-s Einar Hille studied differential equations $F(y'',y)=0$, where $F$ is a polynomial, and conjectured that all meromorphic solutions are elliptic functions, possibly degenerate. I proved this conjecture in 1982. I was a beginning mathematician at that time and was very proud to prove a conjecture of a famous mathematician. On my way to a seminar where I was supposed to talk on this, I stopped in the library to read some old French papers in CR. After I finished my reading, some time remained, and I just started to leaf an old CR volume. To my surprise I found a paper of Picard, who proved "my theorem" in 1890 ! So I did not publish my proof. Later I found that the same result was proved and published by Bank and Kaufman in 1981. Neither they nor Hille knew about this paper of Picard. Both Picard and Hille published textbooks. Picard's textbook contains this theorem, with a proof, and Hille's textbook contains his conjecture.
To conclude: some theorems are considered important, and someone investigates their histories. There is no algorithm for this, it is a creative activity, like any research. Most theorems never attract wide attention, they are forgotten, sometimes rediscovered again and again.