Which great mathematicians were also historians of mathematics? As the question title suggests, which great mathematicians were also historians of mathematics?
We all know plenty of great mathematicians, but not many historians of mathematics. Not to mention that the history of mathematics can be dismissed as mere sociology sometimes and isn't very popular.
 A: Peter M. Neumann (1940–2020) made many notable contributions to group theory. One solo result of his I particularly like is that the factors in a wreath product $G \wr H$ are unique up to isomorphism. This is just one of many beautiful results from his work on permutation groups (mainly done before the Classification Theory of Finite Simple Groups). An important paper with Fulman and Praeger used generating function methods to give strong estimates for the proportion of cyclic, semisimple and regular elements in classical matrix groups.
Peter spent several months in Paris working on a scholarly translation of Evariste Galois' Premier Mémoire and Second Mémoire. This work alone establishes his credentials as a very serious historian of mathematics. He also wrote on Issai Schur with Walter Ledermann, co-edited the Collected Papers of William Burnside and ran a very successful course in Oxford on the history of mathematics.
A: Władysław Narkiewicz has written so far three really good (and extremely useful) books on the history of number theory, namely:

*

*The development of prime number theory. From Euclid to Hardy and Littlewood. Springer Monographs in Mathematics. Springer-Verlag, Berlin, 2000.

*Rational number theory in the 20th century. From PNT to FLT. Springer Monographs in Mathematics. Springer, London, 2012.

*The story of algebraic numbers in the first half of the 20th century. From Hilbert to Tate. Springer Monographs in Mathematics. Springer, Cham, 2018.

A: Michèle Audin has written several classic papers and books on symplectic geometry, and she also wrote many interesting books on the history of mathematicians, some famous, some less well-known.
A: Carl Ludwig Siegel
While I'm unaware of any direct writing of Siegel on the history of mathematics, he brought to light what is now known as the Riemann-Siegel formula after studying unpublished notes of Bernhard Riemann. From 1922 until his departure from Germany for a sabbatical at IAS around 1935, Siegel, alongside Hellinger, Epstein and Dehn, ran a history of mathematics seminar at Goethe. Siegel later wrote of this:

As I look back now, those communal hours in the seminar are some of the happiest memories of my life. Even then I enjoyed the activity which brought us together each Thursday afternoon from four to six. And later, when we had been scattered over the globe, I learned through disillusioning experiences elsewhere what rare good fortune it is to have academic colleagues working unselfishly together without thought to personal ambition, instead of just issuing directives from their lofty positions.

A: It seems to me that Otto Toeplitz (1881-1940) has not been mentioned yet. The following paragraph from the Wikipedia article on Toeplitz gives a quick idea of his contributions to the history of mathematics:

In 1929, he cofounded "Quellen und Studien zur Geschichte der Mathematik" with Otto Neugebauer and Julius Stenzel. Beginning in the 1920s, Toeplitz advocated a "genetic method" in teaching of mathematics, which he applied in writing the book Entwicklung der Infinitesimalrechnung ("The Calculus: A Genetic Approach"). The book introduces the subject by giving an idealized historical narrative to motivate the concepts, showing how they developed from classical problems of Greek mathematics. It was left unfinished, edited by Gottfried Köthe and posthumously published in German in 1946 (and translated into English in 1963).

Harold M. Edwards's book on Fermat's Last Theorem was structured having in mind the genetic method. This is what Edwards himself said about the method of his book in the preface to the first edition of it:

«... The basic method of the book is... the genetic method. The dictionary defines the genetic method as "the explanation or evaluation of a thing or event in terms of its origin and development."... It is important to distinguish the genetic method from history. The distinction lies in the fact that the genetic method primarily concerns itself with the subject—its "explanation or evaluation" in the definition above—whereas the primary concern of history is an accurate record of the men, ideas, and events which played a part in the evolution of the subject. In a history there is no place for detailed descriptions of the theory unless it is essential to an understanding of the events. In the genetic method there is no place for a careful study of the events unless it contributes to the appreciation of the subject. This means that the genetic method tends to present the historical record from a false perspective. Questions which were never successfully resolved are ignored. Ideas which led into into blind alleys are not pursued. Months of fruitless effort are passed over in silence and mountains of exploratory calculations are dispensed with. In order to get to the really fruitful ideas, one pretends that human reason moves in straight lines from problems to solutions. I want to emphasize as strongly as I can that this notion that reason moves in straight lines is an outrageous fiction which should not for a moment be taken seriously. Samuel Johnson once said of the writing of biography that "If nothing but the bright side of characters should be shown, we should sit down in despondency, and think it utterly impossible to imitate them in anything. The sacred writers related the vicious as well as the virtuous actions of men; which had this moral effect, that it kept mankind from despair." This book does, for the most part, show only the bright side, only the ideas that work, only the guesses that are correct. You should bear in mind that this is not a history or biography and you should not despair. You may well be interested less in the contrast between history and the genetic method than in the contrast between the genetic method and the more usual method of mathematical exposition. As the mathematician Otto Toeplitz described it, the essence of the genetic method is to look to the historical origins of an idea in order to find the best way to motivate it, to study the context in which the originator of the idea was working in order to find the "burning question" which he was striving to answer... In contrast to this, the more usual method pays no attention to the questions and presents only the answers. From a logical point of view only the answers are needed, but from a psychological point of view, learning the answers without knowing the questions is so difficult that it is almost impossible. That, at any rate, is my own experience...»

It might be noteworthy that Michael Spivak implicitly referred to the genetic approach in the preface to volume one of his A comprehensive introduction to differential geometry:

«... The second premise for these notes is that in order for an introduction to differential geometry to expose the geometric aspect of the subject, an historical approach is necessary... Of course, I do not think that one should follow all the intricacies of the historical process, with its inevitable duplications and false leads. What is intended, rather, is a presentation of the subject along the lines which its development might have followed; as Bernard Morin said to me, there is no reason, in mathematics any more than in biology, why ontogeny must recapitulate philogeny. When modern terminology is introduced, it should be as an outgrowth of this (mythical) historical development.»

A: Jean Dieudonné was not only an important member of Bourbaki, but also wrote several works on the history of mathematics.
A: Wilfrid Hodges is a great model theorist, that has spent the last years of his research doing history of logic.
See his webpage.
A: I would like to add two new names to the list, though not stricto sensu known mathematicians but having done a remarkable work as historians of science:

*

*The famous physicist (who has been as well at the origin of mathematical models) Nobel prize S. Chandrasekhar wrote a very interesting "Newton's Principia for the Common Reader"  revisiting the difficult-to-read original work of Newton.


*Though having abandoned mathematics once graduated from Ecole Polytechnique, Paul Tannery (1843-1904) has written 17 books on the history of science. His work, extremely well documented, deserves to be known.
All his books are written in French (It may exist translations into English). Here are some of them:
"Pour l'histoire de la science hellène(For the history of hellenistic science).
"La géométrie grecque"(Greek geometry)
Oeuvres de Fermat-Tome I
Oeuvres de Fermat-Tome II
Oeuvres de Fermat-Tome III
There are 3 more volumes about Fermat, mainly written by others after the premature death of Paul Tannery.
And this astonishing bilingual Greek-Latin (not French) edition of a part of [Diophantus work].(https://gallica.bnf.fr/ark:/12148/bpt6k252484/f16.item.r=Tannery%20Paul)
A: Andre Weil wrote three books on the history of mathematics:

*

*Number Theory: An Approach Through History from Hammurapi to Legendre

*Elliptic Functions according to Eisenstein and Kronecker

*Essais historiques sur la théorie des nombres

And the history is embedded in his papers.  Steven Landsburg expresses this much better than I could here.
"What was it about Weil that inspired such reverence? First and foremost, it was the depth and influence of his life's work, which surely established him as one of the great mathematicians of the twentieth century---and therefore, given the extraordinary mathematical achievements of the twentieth century, one of the great mathematicians of all time. When the French mathematician Jean Dieudonne compiled a 'Panorama of Pure Mathematics' in 1982, he listed the major areas of mathematics and the men and women who had made either 'major' or 'significant' contributions to those areas since the beginning of time. With 11 major contributions to his credit, Weil's name appeared more often than any other.
"But the aura that surrounded Weil was based on more than raw achievement. His profound grasp of mathematical history made him seem all the more a part of that history; he was the natural heir to the tradition he cherished. In paper after paper, Weil exhibited his own ideas as natural extensions of the foundations long since laid by great masters like Fermat, Euler, and Gauss in the 17th, 18th and 19th centuries."
A: Magnus wrote this together with Chandler. Ron Solomon wrote this very useful text.
A: Many famous number-theorists have written about the history of the theory of numbers. One of the most prominent examples is that of André Weil (1906-1998): not only did he author epoch-making papers in mathematics, but he also wrote  "Number theory, an approach through history: from Hammurapi to Legendre" (doi:10.1007/978-0-8176-4571-7). This book is, in my opinion, a very serious text on the historical side.
It seems to me that Weil was very interested in the history of number theory throughout his life. According to Wikipedia, he wrote at least another book on the subject ("Essais historiques sur la théorie des nombres [1975]"); his interest in history is also manifest in his famous 1940 letter to his sister (cf. A 1940 letter of André Weil on analogy in mathematics [Notices of the Amer. Math. Soc. 52 (2005), no. 3,  pp. 335-341.]) and, if my memory serves me right, he even offered (or used to offer) a course entitled "300 Years of Number Theory" at the IAS at some point in time.
EDIT: Since J. Stopple entered his answer as I was writing the above paragraphs, I am going to mention another famous mathematicians that wrote a very important opus on the history of the theory of numbers: Leonard Eugene Dickson (1874-1954). According to A. A. Albert, Dickson's three-volume  History of the Theory of Numbers would have been a life's achievement for itself for a more ordinary man...
A: The great italian algebraic geometer Federigo Enriques (1871-1946) also had a deep interest in the history and philosophy of Mathematics. Among his contributions to this fields, one can cite the following works (in Italian and French):

*

*Il principio di ragion sufficiente nel pensiero greco

*Il significato della critica dei principii nello sviluppo delle matematiche

*L'infini dans la pensée des grecs

*L'infinito nella storia del pensiero

*L'oeuvre mathematique de Klein
A: Eugene Dynkin (1924-2014) is known for his work in probability theory,  Lie groups and Lie algebras, and many other areas.  Throughout his career, he conducted and recorded interviews with a great many  mathematicians with whom he came into contact, discussing their mathematical work and their personal and professional lives.  The recordings are now archived by the Cornell University Library as  The Eugene B. Dynkin Collection of Mathematics Interviews.
A: Armand Borel wrote several essays on the history of Lie groups and algebraic groups that were collected and published as a book.
A: Bartel Leendert van der Waerden
 was an algebraist. But, he also was a historian of mathematics, and an editor of the Journal Archive for History of Exact Sciences. 
I would like also to name Clifford Truesdell, who was a pioneer of (rational) continuum mechanics (mathematical theory of elasticity and fluid dynamics). He was also a great Historian of mathematics, and founder of the Journal I mentioned above. He was also one of the editors of Euler's collected Works, Opera Omnia. He knew several languages and was one of the few to write a mathematical paper in Latin in the twentieth century.
A: Vladimir Maz'ya wrote a book about Jacques Hadamard, and received a prize for it, together with Tatiana Shaposhnikova. He wrote many other books as well.
A: Dirk Jan Struik (1894-2000) was professor of mathematics at MIT. He wrote A Concise History of Mathematics and is a recipient of the Kenneth May prize from the International Commission on the History of Mathematics.
I quote from a review:

Euclid was reputed to have told King Ptolemy that there were no “royal
roads” to mathematical knowledge (though many over the centuries seem
to have thought that Euclid’s Elements provided the path of least
resistance). The same is true, perhaps even more so, for the history
of mathematics. But for those prepared to undertake this long and
arduous journey, nothing is more indispensable than a good guidebook. Struik’s Concise History—written with insight, perspective, and
an intimate knowledge of and affection for the subject—is admirably
designed to fulfill that purpose.

