Your admission to the US, and your readmission for the remainder of your initial 90-day period of admission, are governed by the terms of the visa waiver program (VWP). ESTA is nothing more than authorization to travel to the US to apply for admission under the VWP. The provision for readmission is established in the Code of Federal Regulations at 8 CFR 217.3(b).
The actual waiver of the visa requirement and authorization to enter and remain in the US are effected by the immigration officer. That is, in fact, why it doesn't matter whether the ESTA expires while you're in the US.
Even if you will be readmitted for the remainder of your previous 90-day period of admission, you need valid ESTA authorization. Without it, you will be unable to board your flight. The requirement for ESTA is established at 8 USC 1187(a)(11):
(11) Eligibility determination under the electronic system for travel authorization
[...E]ach alien traveling under the program shall, before applying for admission to the United States, electronically provide to the system biographical information and such other information as the Secretary of Homeland Security shall determine necessary to determine the eligibility of, and whether there exists a law enforcement or security risk in permitting, the alien to travel to the United States. Upon review of such biographical information, the Secretary of Homeland Security shall determine whether the alien is eligible to travel to the United States under the program.
It is further elaborated at 8 CFR 217.5, which says at paragraph (b) that
Each alien falling within the provisions of paragraph (a) of this section must receive a travel authorization prior to embarking on a carrier for travel to the United States.
Paragraph (a), in turn, says
Each nonimmigrant alien intending to travel by air or sea to the United States under the Visa Waiver Program (VWP) must, within the time specified in paragraph (b) of this section, receive a travel authorization, which is a positive determination of eligibility to travel to the United States under the VWP via the Electronic System for Travel Authorization (ESTA), from CBP. In order to receive a travel authorization, each nonimmigrant alien intending to travel to the United States by air or sea under the VWP must provide the data elements set forth in paragraph (c) of this section to CBP, in English, in the manner specified herein, and must pay a fee as described in paragraph (h) of this section.
There's nothing here that changes the requirements for those "intending to travel by air or sea" to apply for readmission under a previous period of admission.