I don't know what it was back in the day, but current mids actually do sign an "Agreement to Serve" doc (press hard, make 3 copies..), prior to IDay, that covers this.
It also appears to kick in upon "commencement of the Second Class Academic Year", whether or not one actually attends class that day.
The other interesting thing is that it appears that a voluntary resignation by a 4/C or 3/c Mid isn't automatically accepted, rather it is "accepted when found to be in the best interests of the naval service" - so, legally, they could keep you if they want
The one caveat is that the Agreement to Serve states that the policy is "subject to change without any advance notice" so maybe that is why they are required to sign a new doc at the beginning of 2/C year.
Relevant text:
https://www.usna.edu/Admissions/PermitToReport/_files/documents/AgreementToServe.pdf
II. For Midshipmen Who Enter the Naval Academy Directly from a Civilian Status
a. I understand that if I am discharged from the Naval Academy or if my resignation therefrom is accepted, the following policies are presently applicable:
1. Fourth and Third Class Midshipmen (1st and 2nd years). Any Fourth or Third Class Midshipman who is discharged from the Naval Academy or whose resignation therefrom is accepted will be discharged from the Naval Service. (A resignation tendered by a Fourth or Third Class Midshipman will be accepted when found to be in the best interests of the naval service).
2. Second and First Class Midshipmen (3rd and 4th years)
a. A Second Class Midshipman who is discharged from the Naval Academy or whose resignation therefrom is accepted prior to the commencement of the Second Class Academic Year (which is considered to commence on the first day classes formally convene for the Fall semester) will be discharged from the Naval Service.
b. Following the commencement of the Second Class Academic Year, a Second or First Class Midshipman who is discharged from the Naval Academy or whose resignation therefrom is accepted prior to completing the course of instruction may be transferred to the reserve component of the Navy or the Marine Corps in an enlisted status and ordered to active duty for not less than (2) years, except in those cases where the midshipman is physically disqualified, unfit, or unsuited for military service in an enlisted status. In cases where the Secretary determines that the midshipman has breached his or her agreement per Section I.A. and also determines that the midshipman is unsuitable for enlisted service, the Secretary of the Navy may direct that the midshipman reimburse the Government of the United States for educational benefits received at the Naval Academy to be calculated as described in Section IV, below.
b. I understand that the discharge and active duty obligation policies stated in Section II.A. above are subject to change without advance notice during the course of my attendance at the Naval Academy and if I am discharged from the Naval Academy or if my resignation therefrom is accepted, determinations with respect to my discharge and/or active duty obligation may be made per such revised policies in lieu of those policies in Section II.A., above.