אמרו שנים עשר אלף זוגים תלמידים היו לו לרבי עקיבא מגבת עד אנטיפרס וכולן מתו בפרק אחד מפני שלא נהגו כבוד זה לזה, והיה העולם שמם עד שבא ר"ע אצל רבותינו שבדרום ושנאה להם ר"מ ור' יהודה ור' יוסי ורבי שמעון ורבי אלעזר בן שמוע והם הם העמידו תורה אותה שעה. תנא כולם מתו מפסח ועד עצרת. אמר רב חמא בר אבא ואיתימא ר' חייא בר אבין כולם מתו מיתה רעה. מאי היא? א"ר נחמן אסכרה.
They said by way of example that Rabbi Akiva had twelve thousand pairs of students in an area of land that stretched from Gevat to Antipatris in Judea, and they all died in one period of time, because they did not treat each other with respect. And the world was desolate of Torah until Rabbi Akiva came to our Rabbis in the South and taught his Torah to them. This second group of disciples consisted of Rabbi Meir, Rabbi Yehuda, Rabbi Yosei, Rabbi Shimon, and Rabbi Elazar ben Shamua. And these are the very ones who upheld the study of Torah at that time. Although Rabbi Akiva’s earlier students did not survive, his later disciples were able to transmit the Torah to future generations. With regard to the twelve thousand pairs of Rabbi Akiva’s students, the Gemara adds: It is taught that all of them died in the period from Passover until Shavuot. Rav Ḥama bar Abba said, and some say it was Rabbi Ḥiyya bar Avin: They all died a bad death. The Gemara inquires: What is it that is called a bad death? Rav Naḥman said: Diphtheria. Rav Mattana said: The halakha is in accordance with the opinion of Rabbi Yehoshua, who said that one must attempt to have more children even if he has already fulfilled the mitzva to be fruitful and multiply. § Apropos the discussion with regard to the mitzva to have children, the Gemara cites statements about marriage in general. Rabbi Tanḥum said that Rabbi Ḥanilai said: Any man who does not have a wife is left without joy, without blessing, without goodness. He proceeds to quote verses to support each part of his statement. He is without joy, as it is written: “And you shall rejoice, you and your household” (Deuteronomy 14:26), which indicates that the a man is in a joyful state only when he is with his household, i.e., his wife. He is without blessing, as it is written: “To cause a blessing to rest in your house” (Ezekiel 44:30), which indicates that blessing comes through one’s house, i.e., one’s wife. He is without goodness, as it is written: “It is not good that man should be alone” (Genesis 2:18), i.e., without a wife. In the West, Eretz Yisrael, they say: One who lives without a wife is left without Torah, and without a wall of protection. He is without Torah, as it is written: “Is it that I have no help in me, and that sound wisdom is driven from me?” (Job 6:13), indicating that one who does not have a wife lacks sound wisdom, i.e., Torah. He is without a wall, as it is written: “A woman shall go round a man” (Jeremiah 31:21), similar to a protective wall. Rava bar Ulla said: One who does not have a wife is left without peace, as it is written: “And you shall know that your tent is in peace; and you shall visit your habitation and shall miss nothing” (Job 5:24). This indicates that a man has peace only when he has a tent, i.e., a wife. On the same verse, Rabbi Yehoshua ben Levi said: Whoever knows that his wife fears Heaven and she desires him, and he does not visit her, i.e., have intercourse with her, is called a sinner, as it is stated: And you shall know that your tent is in peace; and you shall visit your habitation. And Rabbi Yehoshua ben Levi said: A man is obligated to visit his wife for the purpose of having intercourse when he is about to depart on a journey, as it is stated: “And you shall know that your tent is in peace, etc.” The Gemara asks: Is this last statement derived from here? It is derived from there: “And your desire shall be to your husband” (Genesis 3:16), which teaches that a wife desires her husband when he is about to depart on a journey. Rav Yosef said: The additional derivation cited by Rabbi Yehoshua ben Levi is necessary only near the time of her set pattern, i.e., when she expects to begin experiencing menstrual bleeding. Although the Sages generally prohibited intercourse at this time due to a concern that the couple might have intercourse after she begins bleeding, if he is about to depart on a journey he must have intercourse with her. The Gemara asks: And how much before the expected onset of menstrual bleeding is considered near the time of her set pattern? Rava said: An interval of time, i.e., half a daily cycle, either a day or a night. The Gemara comments: And this statement that a man must have intercourse with his wife before he departs on a journey applies only if he is traveling for an optional matter, but if he is traveling in order to attend to a matter pertaining to a mitzva, he is not required to have intercourse with his wife so that he not become preoccupied and neglect the mitzva. § The Sages taught: One who loves his wife as he loves himself, and who honors her more than himself, and who instructs his sons and daughters in an upright path, and who marries them off near the time when they reach maturity, about him the verse states: And you shall know that your tent is in peace. As a result of his actions, there will be peace in his home, as it will be devoid of quarrel and sin. One who loves his neighbors, and who draws his relatives close, and who marries the daughter of his sister, a woman he knows and is fond of as a family relative and not only as a wife,

וכ"כ ג"כ הרי"ן שועיב וז"ל שמעתי שיש במדרש שמתו מפסח עד פרוסת העצרת והוא ט"ו יום קודם העצרת כאמרם עד פרוס הפסח פרוס החג שהם ט"ו יום בניסן ובתשרי וכשתסיר ט"ו יום ממ"ט יום נשארו ל"ד והנה הם ל"ג שלימים ומגלחים ביום ל"ד בבקר כי מקצת היום ככולו עכ"ל.
Soon after the comments of the דרשות עה״ת, the טור wrote down this מנהג.
(ב) ויש מקומות שנהגו שלא להסתפר, ויש מסתפרי' מל"ג בעומר ואילך שאומרים שאז פסקו מלמות.
A couple of hundred years later, the בית יוסף codified this מנהג.
(א) ומה שכתב יש מקומות שנהגו שלא להסתפר כ"כ הרי"ן שועיב בדרשת יום ראשון של פסח וכן המנהג פשוט בינינו.
נוהגים שלא להסתפר עד ל"ג לעומר שאומרים שאז פסקו מלמות.
(2) It is customary not to cut one's hair until Lag BaOmer, since it is said that that is when they stopped dying. One should not cut one's hair until the 34th day, in the morning, unless the 33rd day falls on Friday, in which case one may cut one's hair then, in honor of the Sabbath ("kavod Shabbat"). Rema: But in these countries, we do not follow the custom he advocates; rather, we cut our hair on the 33rd day, and we rejoice a bit, and we do not say Tachanun (Maharil and Minhagim). And one should only cut one's hair on the 33rd day itself, but not on its evening. However, if it falls on Sunday, our custom is to cut our hair on Friday in honor of the Sabbath (Maharil). Someone who is performing a brit milah (i.e., the sandak, mohel and the infant's father), or circumcizing his son, is allowed to cut his hair during sefirah in honor of the circumcision (Hagahot Minhagim).
ומה שכתב יש מקומות שנהגו שלא להסתפר כלומר בענין נשואין נהגו בכל המקומות איסור אבל בתספורת יש מקומות שנהגו איסור ויש מקומות שנהגו היתר ועכשיו נוהגין כל המקומות שלא להסתפר.
While we can see that this מנהג was prevalent in various locations, it is still somewhat strange as to why there was a gap of nearly 1,000 years where there is nearly no discussion on this מנהג. For a historical explanation of this custom, see the following 3 סעיפים of the ערוך השולחן.
(א) אלו הימים שבין פסח לעצרת, מוחזק אצל כל ישראל זה שנות מאות רבות לימי דין וימי אבל, מפני שבזמן הקצר הזה מתו שנים עשר אלף זוגות תלמידי חכמים תלמידי רבי עקיבא, כדאיתא ביבמות (סב ב), וכולם מתו במיתת אסכרא (שם).ועוד: ראינו שעיקרי ימי הגזירות בשנות מאות שעברו בצרפת ואשכנז הוו בימים אלו, כמבואר מהפיוטים שעשו קדמונינו על שבתות אלו שבין פסח לעצרת. והם מלאים קינים והגה והי. ויש עוד טעמים על ימים אלו שהם ימי דין (עיין ח"י סעיף קטן ג).
(ב) ולפיכך נהגו כל ישראל מימות הגאונים שלא לישא אשה בין פסח לעצרת. ולא חילקו בין נשואין דמצוה, כגון מי שלא קיים עדיין פריה ורביה, אם לאו. ואף על גב דבאבלות גמורה יש חילוקים, מכל מקום בכאן החמירו על עצמן. ומכל מקום מי שקפץ וכנס – אין עונשין אותו, כיון שעשה מצוה. וכל שכן כשראה שיכול השידוך להתבטל.אבל לארס ולקדש – שפיר דמי. וכן אצלנו לעשות שידוכים ולכתוב תנאים – מותר, שמא יקדמנו אחר. ומותר לעשות סעודה, אך לא בריקודין ומחולות. וכל שכן שאסור לזמר בכלי זמר. וכן סעודת הרשות מותר, כמו סעודות מריעות, ובלבד בלא ריקודין ומחולות.
(ג) וכן נהגו במדינות אלו שלא להסתפר בימים אלו, והוא גם כן עניין אבלות. ומי שהסתפר – קונסין אותו על שעבר על המנהג ולא עשה מצוה. ופשוט הוא דאם צריך לבריאותו להסתפר דמותר. וכן כשיש מילה בימים אלו מותרים בעלי הברית, דהיינו המוהל והסנדק ואבי הבן, להסתפר ביום שלפני המילה סמוך לערב, מפני שיום טוב שלהם הוא.
1. The מנהג was formal and decided by a group and we no longer have access to the sources that began this מנהג.
2. The מנהג began more granularly. Maybe one- or a few- communities banded together to try and deepen their connection to the concern of לא נהגו כבוד זה בזה and in turn began this מנהג.