When you see a conventional clock, you spot only 12 hours. However, the day is divided into 24 hours. The division occurs at midday. Post meridian and ante meridian are Latin terms that refer to the post midday or before midday respectively. Now, when it is post midday or pm, and 12 on the clock, you see that it is afternoon.
Hence, 12 pm becomes midday. The other time it is 12 o clock is before midday and that is at night. Hence, this is regarded as 12 am. This is why the 12 am on the clock s associated with midnight.