12/24 hours come from the idea that there are 12 day hours and 12 night hours. Historically most clock systems counted hours since sunrise. Counting since midnight is a recent change.
Where the 12 comes from? No idea. That's a decision that was made several thousands years ago. It could be from some smart counting of fingers, joints, etc. It could come from the fact that 12 has a lot of dividers. It could be religious reasons (zodiac has 12 animals). Honestly no idea.