Where and/or when did the tradition that Methuselah died seven days before the Flood (for a period of mourning) originate? A few answerers to the question Significance of Methuselah's death year replied with the claim that Methuselah died seven days before the Flood began, thus leaving Noah and his family as the only remaining righteous people on Earth. (Most of these answers are deleted as they weren't sufficiently high-quality.) Furthermore, two of them also said that the 7 days between Methuselah's death and the Flood was for a period of mourning. At least one commenter said that they had heard of this tradition before, but did not know of any support for it, and a request for references did not get a response.

I've never heard of this tradition anywhere else other than these answers. Where and/or when did it originate? Specifically, the tradition that 1) Methuselah died 7 days before the Flood and that 2) the 7 days were for a period of mourning.
Not all extant versions of the Book of Genesis say that Methuselah died the year of the Flood. Wikipedia gives the following:


In the Masoretic text, he died at 969, in the year of the Flood
Septuagint (Alexandrinus), he died at 969, six years before the Flood
Septuagint (Vaticanus), he died at 969, fourteen years after the Flood
Samaritan text, he died at 720 years, in the year of the Flood


Of these, only the Masoretic text and the Samaritan text have Methuselah die in the year of the Flood. I believe the Samaritan text is not original, because neither his age when his son was born (67 years) nor his age at death is divisible by the 'magic' number 17, whereas in the Masoretic they are.

The Septuagint (Vaticanus) can be ruled out because there is no mention of Methuselah on the ark, and he could not have survived otherwise. This seems a pious attempt to avoid the appearance that a righteous man died in the Flood. The Septuagint (Alexandrinus) is technically possible, but is more likely another pious attempt to avoid the appearance that a righteous man died in the Flood. So, the Masoretic text is probably original.

Wilfred Shuchat explains in The Creation According to the Midrash Rabbah, page 124, that according to this midrash, the Flood was delayed by seven days to allow a period of mourning for Methuselah. Midrashim are a Jewish method of interpreting biblical stories, and were written down in the early centuries CE.