12:00AM is midnight because AM is morning, and it’s the beginning of the morning.
Using 12-hour time is just a historical artifact from all our analog clocks having 12 hours on their face and not wanting to have to add 12 to the number on the clock for half the day.
Put more specifically, A.M. and P.M. are abbreviations for “ante meridiem” and “post meridiem”, which are Latin for “before mid-day” and “after mid-day” respectively. Since a new day begins at midnight, it follows that midnight is 12:00 A.M. since it’s the 12 o’clock that is before mid-day.