I only include some of those who died at the age under 40 (death at such a young age is always tragic).
Niels Henrik Abel died of tuberculosis at the age of 27.
Henry Moseley was KIA at Gallipoli at the age of 27. He was a likely candidate for Nobel Prize in 1916 (which was not awarded).
Rene Gateaux was KIA in the Battle of Grand Couronné at the age of 25. (France lost many young mathematicians in WWI. The list can be continued).
Frank Ramsey, mathematician who died at the age of 27. He was the founder of
Ramsey theory, a hot topic in todays research. Wikpedia lists his important contributions to other sciences, but not to pure math! It is truly amazing how much he accomplished by the age of 27.
Alexander Friedmann died at the age of 37 (of poisoning and/or poor treatement).
Matvei Bronstein was executed by Soviet communists at the age of 32.
Lev Shubnikov was executed by Soviet communists at the age of 36.
Semyon Shubin [ru] died in Soviet prison at the age of 30.
Hans Hellman was executed by Soviet communists at the age of 35.
Alexander Witt [ru] died in a Soviet prison camp at the age of 36.
(Russian Wikipedia
has a list of physicists killed or imprisoned by Soviet authorities; I selected from this list those who were killed at the age less than 40, and gave links to English Wikipedia when available.)
I don't have a list of mathematicians, but the number of victims of Soviet regime was very large.