The Midrash identifies Elimelech as one of the leading and wealthy citizens of Bethlehem. When the famine struck, the poor came to him seeking support, and rather than sustain them he fled to Moab to escape their requests — this flight from communal responsibility is presented as the reason he was punished with the deaths of himself and his sons.
רָעָב שֶׁהָיָה בִּימֵי אֵלִיָּהוּ שֶׁל בַּצֹרֶת הָיָה, שָׁנָה עָבְדַת שָׁנָה לָא עָבְדַת, אֲבָל רָעָב שֶׁבָּא בִּימֵי אֱלִישָׁע, שֶׁל מְהוּמָה הָיָה, שֶׁנֶּאֱמַר (מלכים ב ו, כה): עַד הֱיוֹת רֹאשׁ חֲמוֹר בִּשְׁמֹנִים כֶּסֶף. רָעָב שֶׁבָּא בִּימֵי שְׁפֹט הַשֹּׁפְטִים, רַבִּי הוּנָא בְּשֵׁם רַבִּי דוֹסָא אַרְבָּעִים וּשְׁתַּיִם סְאוֹת הָיוּ וְנַעֲשׂוּ אַרְבָּעִים וְאַחַת, וְהָא תָּנֵי לֹא יֵצֵא אָדָם לְחוּצָה לָאָרֶץ אֶלָּא אִם כֵּן הָיוּ סָאתַיִם לְקוּחוֹת בְּשֶׁקֶל, אָמַר רַבָּן שִׁמְעוֹן בֶּן גַּמְלִיאֵל אֵימָתַי בִּזְּמַן שֶׁאֵינוֹ מוֹצֵא לִקַּח אֲבָל מוֹצֵא לִקַּח אֲפִלּוּ סְאָה בְּשֶׁקֶל לֹא יֵצֵא יִשְׂרָאֵל חוּצָה לָאָרֶץ. וְהָא תַנְיָא בִּשְׁעַת הַדֶּבֶר בִּשְׁעַת מִלְחָמָה כְּנֹס הָרֶגֶל, וּבִשְׁעַת רְעָבוֹן פַּזֵּר הָרֶגֶל, לָמָּה נֶעֱנַשׁ אֱלִימֶלֶךְ, עַל יְדֵי שֶׁהִפִּיל לִבָּן שֶׁל יִשְׂרָאֵל עֲלֵיהֶם, לְבוּלְיָטִין שֶׁהָיָה שָׁרוּי בִּמְדִינָה, וְהָיוּ בְּנֵי הַמְדִינָה סְבוּרִין עָלָיו וְאוֹמְרִים שֶׁאִם יָבוֹאוּ שְׁנֵי בַּצֹּרֶת הוּא יָכוֹל לְסַפֵּק אֶת הַמְּדִינָה עֶשֶׂר שָׁנִים מָזוֹן כֵּיוָן שֶׁבָּאת שְׁנַת בַּצֹּרֶת יָצְתָה לָהּ שִׁפְחָתוֹ מְעַיְּלַת בְּסִידְקִי וְקֻפָּתָהּ בְּיָדָהּ, וְהָיוּ בְּנֵי הַמְּדִינָה אוֹמְרִים, זֶהוּ שֶׁהָיִינוּ בְּטוּחִים עָלָיו שֶׁאִם תָּבוֹא בַּצֹּרֶת הוּא יָכוֹל לְפַרְנֵס אוֹתָנוּ עֶשֶׂר שָׁנִים, וַהֲרֵי שִׁפְחָתוֹ עוֹמֶדֶת בְּסִידְקִי וְקֻפָּתָהּ בְּיָדָהּ. כָּךְ אֱלִימֶלֶךְ הָיָה מִגְּדוֹלֵי הַמְּדִינָה וּמִפַּרְנָסֵי הַדּוֹר, וּכְשֶׁבָּאוּ שְׁנֵי רְעָבוֹן אָמַר עַכְשָׁיו כָּל יִשְׂרָאֵל מְסַבְּבִין פִּתְחִי, זֶה בְּקֻפָּתוֹ וְזֶה בְּקֻפָּתוֹ, עָמַד וּבָרַח לוֹ מִפְּנֵיהֶם, הֲדָא הוּא דִכְתִיב: וַיֵּלֶךְ אִישׁ מִבֵּית לֶחֶם יְהוּדָה.
Why was Elimelekh punished? It is because he sank the hearts of Israel. [It is analogous] to a prominent person who lived in a province, and the residents of the province would depend upon him, and would say that if drought years would come, he could provide food for the province for ten years. When a drought year came, his maidservant went out, and went into the market with her basket in her hand. The residents of the province said: This is the one who we relied upon, that if there would be a drought he could support us for ten years? His maidservant is standing in the market with her basket in her hand! So, Elimelekh was one of the prominent residents of the province, and one of the leaders of the generation. When the years of famine arrived, he said: ‘Now, all Israel will come around to my door, this one with his basket and that one with his basket.’ He arose and fled from them; that is what is written: “A man of Bethlehem of Judah went.”