When the imams of the past died their students put their rulings into books and followed their rulings.
Many scholars came over time and revised, codified and added to their rulings. They are all a means of following the Sunnah of the Prophet (saw).
For example, Abu Hanifah was in Iraq and studied with the great scholar Hammad and then had two great students, Hassan al Shaybani and Imaam Muhammed. Years later his rulings were codified and used to form the basis of rulings for his madhab.
You will not find a single great scholar of the past except he began by following a madhab; Ibn Taymiyyah, Ibn Katheer and so on.