You don't need the comma when you write it this way.
The comma in June 12, 2024, is there exactly because it's the wrong order.
It's basically "I wrote the date. Oops, forgot the year!"
Computers order it correctly in that format because that's the correct format. In the same way a computer will order any other correctly formatted numbers in the correct order - and incorrectly formatted numbers in the incorrect order - it shouldn't be surprising that they order correctly formatted dates in the correct order.
I figure it's because the year can be seen as an optional appendage if you're talking about dates from the current year. Like, I can say "that happened on May 5th," or "I'll be there June 18th," and you can reasonably assume I mean in 2024 unless I specify "June 18th, 2063."
Now, as for why you can say "I'm going on the 18th," but Americans don't say 18th of June, 2024, I haven't a clue. We really only seem to have logical explanations for the way we do things about half of the time.
Several cultures throughout history have used base 12 for their numbering! You can count to 12 on one hand by counting the segments of your fingers (excluding the thumb).